我有一個綁定到DataGrid的DataTable。 CheckBox在數據行中創建。當我檢查複選框後面的代碼被擊中時,但我不知道如何獲取DataRow。如何將DataRow從UI控件獲取到ASP.NET中的ascx.cs?
<asp:DataGrid ID="dgCaseStatusTypes"
runat="server"
AutoGenerateColumns="False"
CellPadding="5"
DataKeyField="InmateCaseStatusID"
OnItemCommand="dgCaseStatusTypes_ItemCommand">
<Columns>
<asp:BoundColumn DataField="Code" HeaderText="Code"></asp:BoundColumn>
<asp:BoundColumn DataField="Text" HeaderText="Text"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Prebook Visible" >
<ItemTemplate>
<asp:CheckBox id="chkBox1"
runat="server"
AutoPostBack="true"
checked= '<%# Eval("IsPreBookVisibleBool") %>'
OnCheckedChanged="OnCheckedChanged_Event"
></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
protected void OnCheckedChanged_Event(object sender, System.EventArgs e)
{
CheckBox cb = sender as CheckBox;
//how to get the DataRow that created this control?
}
如果您還處於開發早期,請考慮從'DataGrid'切換到'GridView'。 'GridView'是建立在ASP.NET 2.0中以取代'DataGrid'。 –