Hi,
In my current project, I have to display a RadGrid which looks as follows http://www.gouw.ws/RadGridWithCheckBoxes.jpg
The RadGrid with paging has 3 columns as follows:
- Column Name of type GridBoundColumn which can be sorted.
- Columns Select1 and Select2 of type GridCheckBoxColumn whose values can be modified by the user.
The RadGrid is used to display a data item which is a collection of 1 string value (Name) and 2 boolean values.
I need to modify the RadGrid to look as follows http://www.gouw.ws/RadGridWithCheckBoxesModified.jpg
1. Instead of displaying the string Select1 and Select2 as the titles of the GridCheckBoxColumn,
I need to display a CheckBox on each Column title and when it is un/checked then all the
CheckBoxes in the column on the corresponding page will be automatically un/checked.
2. Depending on the value of Name on each row, I need to selectively make Select1 CheckBox
or Select2 CheckBox not visible (but not both).
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 : 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), false, false)); |
} |
return data; |
} |
} |
Can you please show me how to do this?
Regards,
Herman Gouw