【发布时间】:2016-02-06 07:57:54
【问题描述】:
我有一个绑定到 ObjectDataSource 的 GridView。我向网格中的每一行添加了一个文本框和一个按钮,以允许用户输入日期并单击按钮进行订阅。 GridView 中不存在此文本框的字段,并且在运行此页面时返回空引用。 我该怎么办?请帮忙.. 这是 ASPX 文件和背后的代码:
<asp:TemplateField HeaderText="content" ItemStyle-Width="150">
<ItemTemplate>
<asp:TextBox ID="Name" runat="server" />
</ItemTemplate>
<ItemStyle Width="150px"></ItemStyle>
</asp:TemplateField>
<asp:ButtonField CommandName="Select" Text="save" ButtonType="Button" />
代码隐藏:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
string s = row.Cells[0].Text;
//Fetch value of Name.
TextBox tb = (TextBox)GridView1.FindControl("Name");
string name = tb.Text;
}
name 的值为 null...
【问题讨论】: