我有一個帶有模板字段的gridview。在該模板字段中是複選框。我在gridview之外有一個提交按鈕來分配被檢查的記錄。在回發沒有複選框註冊爲被檢查。這裏是我的代碼:GridView中的TemplateField中的複選框在回發中丟失檢查
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="cb" Checked="false" runat="server" />
<asp:Label ID="lblCFID" runat="server" Visible="false" Text='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderStyle-HorizontalAlign="Center" DataField="Name" HeaderText="Name" />
<asp:BoundField HeaderStyle-HorizontalAlign="Center" DataField="DOB" HeaderText="Date of Birth" />
<asp:BoundField HeaderStyle-HorizontalAlign="Center" HeaderText="Gender" DataField="Gender" />
<asp:BoundField HeaderStyle-HorizontalAlign="Center" HeaderText="Status" DataField="Status" />
<asp:BoundField HeaderStyle-HorizontalAlign="Center" HeaderText="Plan Name" DataField="PlanName" />
<asp:BoundField HeaderStyle-HorizontalAlign="Center" HeaderText="Type" DataField="ControlType" />
<asp:BoundField HeaderStyle-HorizontalAlign="Center" HeaderText="Date of Service" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" DataField="DateofService" />
</Columns>
protected void AssignRecords(object sender, EventArgs e)
{
int Rows = gvASH.Rows.Count;
for (int i = 0; i < Rows; i++)
{
//CheckBoxField cb = ((CheckBoxField)gvASH.Rows[i].Cells[1]).;
CheckBox cb = (CheckBox)gvASH.Rows[i].Cells[0].FindControl("cb");
Label lblID = (Label)gvASH.Rows[i].Cells[0].FindControl("lblCFID");
if (cb.Checked == true)
{
string ID = lblID.Text;
//Assign Code
}
}
}
我有一個斷點設置在字符串ID = lblID.Text;但它從來沒有發現任何被檢查。
我使用C#,但在VB.Net的asp.net網站這個例子中,基本上是做什麼我做:HTTP:// WWW .asp.net /學習/數據訪問/教程-52-vb.aspx 所以我知道這是可能的,我只是不知道爲什麼它不適合我。 – Jhorra 2009-10-15 22:32:07
頁面生命週期是什麼時候分配被調用的方法? – 2009-10-15 23:12:58
查看這裏的解決方案,你需要堅持選擇複選框http://highoncoding.com/Articles/697_Persisting_CheckBox_State_While_Paging_in_GridView_Control.aspx – user2323258 2013-04-26 09:50:52