这是我的aspx代码
.....
<asp:TemplateColumn>
<HeaderTemplate>
<asp:DropDownList
ID="HeaderDropDown" Runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList
ID="ItemDropDown" Runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<HeaderTemplate>
Details
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtDetails" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
...............
C#代码是
for (int i = 1; i < DataGrid1.Items.Count; i++)
{
DropDownList lst = DataGrid1.Items[i].Cells[1].FindControl("ItemDropDown") as DropDownList;
String value = lst.SelectedValue;
String StaffId = DataGrid1.Items[i].Cells[0].Text;
TextBox txt= DataGrid1.Items[i].Cells[2].FindControl("txtDetaills") as TextBox;
}
我正确获取 lst 对象,但 txt 始终返回null。
答案 0 :(得分:3)
你有一个错字:
TextBox txt= DataGrid1.Items[i].Cells[2].FindControl("txtDetaills") as TextBox;
应该是:
TextBox txt= DataGrid1.Items[i].Cells[2].FindControl("txtDetails") as TextBox;
因此,txtDetaills
应为txtDetails
答案 1 :(得分:1)
txtDetails
,而非txtDetaills
- 太多了!