日期:2014-05-18  浏览次数:20422 次

GridView中TextBox取值问题
TextBox部分代码:
<asp:TemplateField   HeaderText= "Userid ">  
      <ItemTemplate>
<asp:TextBox   ID= "txtUserid "   runat= "server "   Width= "90px "   />
      </ItemTemplate>
</asp:TemplateField>    

CS文件部分代码:
TextBox   t1   =   (TextBox)GridView1.Rows[0].Cells[0].FindControl( "txtUserid ");
//string   t1   =   ((LiteralControl)GridView1.Rows[0].Cells[0].Controls[0]).Text.Trim();
这两种方法取到的都是空值.
何解?

------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox t1 = (TextBox)e.Row.FindControl( "txtUserid ");

}
}
------解决方案--------------------
((TextBox)GridView1.Rows[0].Cells[0].FindControl( "txtUserid ")).text.tostring()
------解决方案--------------------
rowcommand中
GridViewRow InforGridViewRow = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
Label lbPerson_ID = InforGridViewRow.FindControl( "lbPerson_ID ") as Label;
rowdatabound 中
if (e.Row.RowType == DataControlRowType.DataRow)
}
LinkButton LinkContent = ((LinkButton)(e.Row.Cells[1].FindControl( "LKContent ")));
}