Hi,
In my current project, I have a RadGrid having 2 CheckBoxes similar to the following:
The code is given as follows:
ASPX
<body> |
<form id="form1" runat="server"> |
<div> |
<telerik:RadScriptManager ID="radScriptManager" runat="server" /> |
<telerik:RadGrid ID="radGrid" AutoGenerateColumns="false" AllowMultiRowEdit="true" AllowPaging="true" AllowSorting="true" PageSize="10" OnNeedDataSource="radGrid_NeedDataSource" OnPreRender="radGrid_PreRender" runat="server"> |
<ClientSettings> |
<Scrolling UseStaticHeaders="true" /> |
</ClientSettings> |
<PagerStyle Mode="NumericPages" /> |
<MasterTableView DataKeyNames="Name" EditMode="InPlace" TableLayout="Fixed"> |
<Columns> |
<telerik:GridBoundColumn DataField="Name" DataType="System.String" HeaderText="Name" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" AllowSorting="true" ReadOnly="true" UniqueName="Name" /> |
<telerik:GridCheckBoxColumn DataField="Select1" DataType="System.Boolean" HeaderText="Select1" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" AllowSorting="false" ReadOnly="false" UniqueName="Select1" /> |
<telerik:GridCheckBoxColumn DataField="Select2" DataType="System.Boolean" HeaderText="Select2" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" AllowSorting="false" ReadOnly="false" UniqueName="Select2" /> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
</div> |
</form> |
</body> |
C#
public partial class RadGridWithCheckBoxes : System.Web.UI.Page |
{ |
private List<Data> _data; |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!IsPostBack) |
{ |
this._data = Data.Load(); |
Session["DATA"] = this._data; |
} |
else |
{ |
this._data = (List<Data>)Session["DATA"]; |
} |
} |
protected void radGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
this.radGrid.DataSource = this._data; |
} |
protected void radGrid_PreRender(object sender, System.EventArgs e) |
{ |
foreach (GridDataItem item in this.radGrid.Items) |
{ |
item.Edit = true; |
} |
this.radGrid.Rebind(); |
} |
} |
public class Data |
{ |
public string Name { get; set; } |
public bool Select1 { get; set; } |
public bool Select2 { get; set; } |
public Data(string name, bool select1, bool select2) |
{ |
Name = name; |
Select1 = select1; |
Select2 = select2; |
} |
public static List<Data> Load() |
{ |
List<Data> data = new List<Data>(); |
for (int i = 0; i < 25; i++) |
{ |
data.Add(new Data(String.Format("Data{0}", i), true, false)); |
} |
return data; |
} |
} |
As soon as a checkbox in the grid is checked or unchecked, I would like to save the value back into the data object.
Therefore, the sorting and paging will always display the values correctly.
Can you please show me how to do this?
Regards,
Herman Gouw