1
我繼續得到捕捉選定值從數據網格
對象的錯誤未設置爲對象的實例
什麼我需要改變,使這個代碼能夠成功地執行?
HTML
<td valign="top" style="text-align: left; width: 200px;">
<asp:GridView runat="server" ID="datagridTest" AutoGenerateColumns="false" GridLines="Both" ShowFooter="true" >
<Columns>
<asp:BoundField DataField="field1" HeaderText="1st Set" />
<asp:BoundField DataField="field2" HeaderText="2nd Set" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("categoryID") %>' ID="managerID" Visible="false"></asp:Label>
</ItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="Checked" runat="server" AutoPostBack="false" Checked='<%# Convert.ToBoolean(Eval("Checked")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button runat="server" ID="btnChecked" CssClass="Buttons" Text="Add" OnClick="btnC_Click" />
</td>
C#
protected void btnC_Click(object sender, EventArgs e)
{
try
{
foreach (GridViewRow row in datagridTest.Rows)
{
string ID = ((Label)row.FindControl("managerID")).Text;
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)row.FindControl("Checked");
if (chk.Checked) {}
else {}
}
}
}
catch (Exception exception) { throw exception; }
}
糾正仍然存在相同的問題。 –