GridView设置如下:
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();
两个都是正解
String text=null;
text=((TextBox)(MyGridView.Rows[0].FindControl("MyTextBox"))).values.ToString().Trim();
Response.Write(text);
列:
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;
}
}
}
}