怎么获取GridView中TextBox的值

2024-11-25 18:37:22
推荐回答(4个)
回答1:

GridView设置如下:
  EmptyDataText="暂时没有记录!" Width="100%" Height="100%" AllowPaging="True" OnPageIndexChanging="GridViewlb_PageIndexChanging"
  DataKeyNames="id" PageSize="26" OnRowCreated="GridViewlb_RowCreated" OnRowDataBound="GridViewlb_RowDataBound"
  AllowSorting="True">

  
    
    
    
    
      
      
    

    
    
    
      
        
      

    
    

  



  获得GridView中TextBox的值:
  如果是模板列,可以利用:
string str = ((TextBox)(this.GridView1.Rows[行号].Cells[6].FindControl("textBox1"))).Text.Trim();

  如果不是模板列,可以利用
string str = this.GridView1.Rows[行号].Cells[6].Text.Trim();

回答2:

两个都是正解

回答3:

String text=null;
text=((TextBox)(MyGridView.Rows[0].FindControl("MyTextBox"))).values.ToString().Trim();
Response.Write(text);

回答4:

列:
protected void btnCommit_Click(object sender, EventArgs e)
{
Button bt1 = sender as Button;
if (bt1.CommandName.ToLower() == "bb")
{
foreach (GridViewRow gr in GridView1.Rows)
{
TextBox tb = (TextBox)gr.Cells[0].FindControl("txtPass");
string pass = bt1.CommandArgument.ToString();
string password = tb.Text.Trim();
Panel p1 = (Panel)gr.Cells[0].FindControl("pPassNone");
Panel p2 = (Panel)gr.Cells[0].FindControl("pPass");
if (password == pass)
{
p1.Visible = true;
p2.Visible = false;
}
}
}
}