我有一個DataGrid,它具有用於選擇特定用戶的複選框。點擊Ok按鈕後,我應該得到複選框的狀態,如果選中,則獲取該行的ID。我到達複選框,但值總是Checked = false,當然,即使當我檢查我的複選框。代碼如下:無法獲取數據網格中的複選框值ASP.NET
的.aspx
<Columns>
<asp:TemplateColumn HeaderText="Odabir">
<ItemTemplate>
<asp:CheckBox ID="chkVjezba" runat="server" Enabled="true"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Vježba" DataField="Naziv"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Broj serija">
<ItemTemplate>
<asp:TextBox ID="brojSerija" runat="server" Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Ocjena 6">
<ItemTemplate>
<asp:TextBox ID="ocjena6" runat="server" Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Ocjena 7">
<ItemTemplate>
<asp:TextBox ID="ocjena7" runat="server" Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Ocjena 8">
<ItemTemplate>
<asp:TextBox ID="ocjena8" runat="server" Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Ocjena 9">
<ItemTemplate>
<asp:TextBox ID="ocjena9" runat="server" Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Ocjena 10">
<ItemTemplate>
<asp:TextBox ID="ocjena10" runat="server" Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
我的.cs代碼文件:
foreach (DataGridItem row in vjezbeGrid.Items)
{
if (((CheckBox)row.Cells[0].FindControl("chkVjezba")).Checked)
{
//something
}
}
感謝。
就是這樣!大。我剛剛在頁面加載事件中添加if(!IsPostBack) – rukfash 2014-10-06 14:31:14