C# findcontrol的用法
.aspx中有如下代码:<asp:RepeaterID="Repeater1"runat="server"><ItemTemplate><tr><tdstyle="wid...
.aspx中有如下代码:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td style="width: 30%">
<a href="../View.aspx?id=<%#Eval("id") %>" target="_blank"><%#Eval("Title") %></a>
</td>
<td style="width: 20%"><%#Eval("Class") %>
</td>
<td style="width: 30%"><%#Eval("Time") %>
</td>
<td style="width: 20%"><a href="EditNews.aspx?id=<%#Eval("id") %>">编辑</a>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName='<%#Eval("id") %>' OnClientClick="return confirm('确定要删除吗?')" OnClick="LinkButton2_Click">删除</asp:LinkButton></td>
</tr>
</ItemTemplate>
</asp:Repeater>
在.aspx.cs中有如下代码:
LinkButton lb = Repeater1.FindControl("LinkButton2") as LinkButton;
int ID = Convert.ToInt32(lb.CommandName);
为什么我运行时对这句int ID = Convert.ToInt32(lb.CommandName);会有未将对象引用设置到对象的实例的异常 展开
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td style="width: 30%">
<a href="../View.aspx?id=<%#Eval("id") %>" target="_blank"><%#Eval("Title") %></a>
</td>
<td style="width: 20%"><%#Eval("Class") %>
</td>
<td style="width: 30%"><%#Eval("Time") %>
</td>
<td style="width: 20%"><a href="EditNews.aspx?id=<%#Eval("id") %>">编辑</a>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName='<%#Eval("id") %>' OnClientClick="return confirm('确定要删除吗?')" OnClick="LinkButton2_Click">删除</asp:LinkButton></td>
</tr>
</ItemTemplate>
</asp:Repeater>
在.aspx.cs中有如下代码:
LinkButton lb = Repeater1.FindControl("LinkButton2") as LinkButton;
int ID = Convert.ToInt32(lb.CommandName);
为什么我运行时对这句int ID = Convert.ToInt32(lb.CommandName);会有未将对象引用设置到对象的实例的异常 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询