作者whileloop (回圈)
看板C_Sharp
标题Re: [问题] GridView的样板
时间Sun Apr 19 13:14:41 2009
A.aspx:
<asp:GridView ID="GridView1" runat="server" .....
OnRowDataBound="GridView1_RowDataBound">
A.aspx.cs:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow)
return;
((TextBox)e.Row.FindControl("TextBox_CompleteTime")).Text = "TEST!!";
}
问题依旧.. XD
既然样板里的Button,不用FindControl这个Button就可以产生OnClick的事件
为什麽同一个样板里的TextBox却要用FindControl..
既然一定要用FindControl,R大的方式我仍然有问题,请问我可能是出现了哪些问题?
谢谢! ^^"
※ 引述《rayhill (....)》之铭言:
: ※ 引述《whileloop (回圈)》之铭言:
: : 请问是在GridView1_RowDataBound中写吗?
: : TextBox tb = (TextBox)e.Row.FindControl("TextBox_CompleteTime");
: : tb.Text= System.DateTime.Now.ToString("yyyy/MM/dd HH:mmtt");
: : 会出现错误讯息:
: : System.NullReferenceException: 并未将物件参考设定为物件的执行个体
: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
: {
: if (e.Row.RowType != DataControlRowType.DataRow)
: return;
: ((TextBox)e.Row.FindControl("TextBox1")).Text = "Hello!!";
: }
: 结果是正确的啊..
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.225.161.244
1F:→ regionbbs:你的ItemTemplate中有什麽东西? 04/19 13:16
2F:→ whileloop:EditItemTemplate里放着LinkButton与TextBox各一个 04/19 13:52
3F:→ regionbbs:那你试着用 GridView.RowEditing 事件去抓看看。 04/19 14:09
4F:推 KenZ:你把你的 LinkButton 跟 TextBox 放在 ItemTemplate 04/19 14:29
5F:→ KenZ:不要放在 EditItemTemplate 04/19 14:29