Grid View for ASP.NET Web Forms - How to use ASPxCheckBox in DataItemTemplate to implement a selection column
This example demonstrates how to emulate the selection behavior in ASPxGridView control.
DataItemTemplate contains a ASPxCheckBox control. The CheckedChanged event handler calls the SelectRowOnPage method to select or deselect the corresponding row.
<dx:GridViewDataTextColumn Caption="#" >
<DataItemTemplate>
<dxe:ASPxCheckBox ID="cbCheck" runat="server" AutoPostBack="false" OnLoad="cbCheck_Load" />
</DataItemTemplate>
...
</dx:GridViewDataTextColumn>
protected void cbCheck_Load(object sender, EventArgs e) {
...
cb.ClientSideEvents.CheckedChanged = String.Format("function (s, e) {{ grid.SelectRowOnPage ({0}, s.GetChecked()); }}", container.VisibleIndex);
}
HeaderTemplate contains a ASPxCheckBox control to implement select all functionality. For this check box, the CheckedChanged event handler calls the SelectAllRowsOnPage method to select or deselect all grid rows.
<dx:GridViewDataTextColumn Caption="#" >
...
<HeaderTemplate >
<dxe:ASPxCheckBox ID="SelectAllCheckBox" runat="server" ToolTip="Select/Unselect all rows on the page"
ClientSideEvents-CheckedChanged="function(s, e) { grid.SelectAllRowsOnPage(s.GetChecked()); grid.PerformCallback(); }" />
</HeaderTemplate>
</dx:GridViewDataTextColumn>
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)