gridview 中textbox怎么取TEXT值

kangfu01 2008-04-18 07:12:22
我在dridview的itemtemplate中放了一个textbox1

请问怎么样来取中一行的textbox1中的值

然后怎么样将所有的textbox1中的值相加放入一个LABLE
...全文
187 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
三笑苍天 2008-07-28
  • 打赏
  • 举报
回复
GrifViewRow ->GridViewRow ???
panxuan 2008-04-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xiao_xiao_jjp 的回复:]
int total
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox tb=(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(tb.Text);
}
label1.text=total;
[/Quote]
Magic_YJL 2008-04-19
  • 打赏
  • 举报
回复

int total = 0;
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox TextBox =(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(TextBox .Text);
}
label1.text=total.toString();


zpcoder 2008-04-19
  • 打赏
  • 举报
回复
如果还是不行
int total ;
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox tb=(TextBox)gvr.Controls[0].FindControl("TextBox1");
total+=Int32.Parse(tb.Text);
}
label1.text=total.toString();
likevs 2008-04-19
  • 打赏
  • 举报
回复
this.GridView1.Rows[e.RowIndex].Cells[3].Text

//为记录行索引e.RowIndex
//3为你要取得的值所在的列索引
wangdetian168 2008-04-19
  • 打赏
  • 举报
回复
就是便利了
datahandler2 2008-04-19
  • 打赏
  • 举报
回复
自定义模板列用FindControl方法,然后在遍历GridView各个列来查找就可以了。
具体代码上面就是了
zengxie 2008-04-19
  • 打赏
  • 举报
回复
int total
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox tb=(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(tb.Text);
}
label1.text=total;
zengxie 2008-04-19
  • 打赏
  • 举报
回复
int total
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox tb=(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(tb.Text);
}
label1.text=total;
badtank 2008-04-18
  • 打赏
  • 举报
回复
我的代码也有问题,5楼正确
gui0605 2008-04-18
  • 打赏
  • 举报
回复
用FindControl即可访问GrifView内部的控件
mylibin 2008-04-18
  • 打赏
  • 举报
回复

int total = 0;
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox TextBox =(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(TextBox .Text);
}
label1.text=total.toString();
badtank 2008-04-18
  • 打赏
  • 举报
回复
1楼的有个小bug :)
int total ;
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox tb=(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(tb.Text);
}
label1.text=total.toString();
huanleforever 2008-04-18
  • 打赏
  • 举报
回复
同意1楼的
bgk112 2008-04-18
  • 打赏
  • 举报
回复
同意楼上的。:)
xiao_xiao_jjp 2008-04-18
  • 打赏
  • 举报
回复
int total
foreach(GrifViewRow gvr in GridView1.Rows)
{
TextBox tb=(TextBox)gvr.FindControl("TextBox1");
total+=Int32.Parse(tb.Text);
}
label1.text=total;
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb; public partial class userShow : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.Label1.Text = System.DateTime.Now.ToString(); loadData(); } protected void Button2_Click(object sender, EventArgs e) { OleDbConnection conn; OleDbCommand cmd; string olecmd, oleString,value; value = this.TextBox1.Text; Session.Add("key", value); oleString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("news.mdb"); olecmd = "select * from userLoad where userName='"; olecmd += TextBox1 .Text.Trim(); olecmd += "'and userPassword='"; olecmd += TextBox2 .Text.Trim() + "'"; conn = new OleDbConnection();//实例化对象 conn.ConnectionString = oleString; cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = olecmd; conn.Open(); OleDbDataReader dr = cmd.ExecuteReader(); if (this.TextBox1.Text.Trim() == "" || this.TextBox2.Text.Trim() == "") { Response.Redirect("usersub.aspx"); } if (dr.Read()) { Session["username"] = this.TextBox1.Text; Response.Redirect("todayNews.aspx"); } else { this.TextBox1 .Focus(); this.TextBox1 .Text = ""; this.TextBox2 .Text = ""; } conn.Close(); dr.Close(); } protected void Button3_Click(object sender, EventArgs e) { this.TextBox1.Focus(); this.TextBox1.Text = ""; this.TextBox2.Text = ""; } DataSet GetDataSet() { OleDbConnection conn; OleDbCommand cmd; conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("news.mdb"); conn.Open(); cmd = new OleDbCommand(); cmd.CommandText = "select * from newsData where newsclassid=0"; cmd.Connection = conn; OleDbDataAdapter oleDA = new OleDbDataAdapter(); oleDA.SelectCommand = cmd; DataSet ds = new DataSet(); oleDA.Fill(ds, "newsData"); conn.Close(); return ds; } void loadData() { DataSet ds = GetDataSet(); GridView1.DataSource = ds; GridView1.DataBind(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("userLogin.aspx"); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; loadData(); } }
public partial class 查询收费 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect("查宿舍缴费.aspx"); } protected void Button1_Click(object sender, EventArgs e) { OleDbConnection conn = new OleDbConnection(); string strconn; strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\考试项目\\App_Data\\宿舍管理信息系统.mdb"; conn.ConnectionString = strconn; conn.Open(); string sql, textDormID, textMDate, textEBuy, textCPerson, textCMoney; textDormID = TextBox1.Text.Trim() + "%"; textMDate = TextBox5.Text.Trim() + "%"; textEBuy = TextBox3.Text.Trim() + "%"; textCPerson = TextBox2.Text.Trim() + "%"; textCMoney = TextBox4.Text.Trim() + "%"; sql = "select ChargeID as 收费编号,dormID as 宿舍号,MDate as 收费日期,EBuy as 购买电量,CPerson as 缴费人,CMoney as 电费 from charge " + "where dormID like'" + textDormID + "'and MDate like '" + textMDate + "'and EBuy like '" + textEBuy + "'and CPerson like '" + textCPerson + "'and CMoney like '" + textCMoney + "'"; OleDbDataAdapter adp = new OleDbDataAdapter(sql, conn); DataSet ds = new DataSet(); adp.Fill(ds, "charge"); if (ds.Tables["charge"].Rows.Count > 0) { Label2.Text = "共有" + ds.Tables["charge"].Rows.Count + "条记录!"; GridView1.DataSource = ds.Tables["charge"].DefaultView; GridView1.DataBind(); } else { Label2.Text = "共有0条记录!"; GridView1.DataBind(); } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { } }
基于C#语言的管理系统 是必备的资源 此文档是PDF文档 源文档 using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Text; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class AdminStudent : System.Web.UI.Page { protected static string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dataBind(); } } public void dataBind() { using (SqlConnection conn = new SqlConnection(connStr)) { using (SqlDataAdapter comm = new SqlDataAdapter("select id,stuNum,stuName,stuSex,convert(varchar(10) ,birthday,120)as birthday,branch,IdentityID,native,address,politics,department,className,convert(varchar(10) , registerTime,120)as registerTime,Tel,photoImage from stuInfo", conn)) { conn.Open(); DataSet ds = new DataSet(); comm.Fill(ds, "ds"); GridView1.DataSource = ds; GridView1.DataKeyNames = new string[] { "id"}; GridView1.DataBind(); } } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; dataBind(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView1.EditIndex = -1; dataBind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; dataBind(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = (int)GridView1.DataKeys[e.RowIndex].Value; string sqlstr = "delete from StuInfo where id=" + id + ""; using (SqlConnection conn = new SqlConnection(connStr)) { using (SqlCommand comm = new SqlCommand(sqlstr, conn)) { conn.Open(); int row = comm.ExecuteNonQuery(); } } dataBind(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { StringBuilder sqlstr = new StringBuilder(); sqlstr.Append("update StuInfo set stuNum='"+((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.Trim()+"',"); sqlstr.Append("stuName='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim() + "',"); sqlstr.Append("stuSex='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.Trim() + "',"); sqlstr.Append("birthday=" +

62,040

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧