I can create different controls per column depending on data from code behind and it works.
I want to create different controls per each row in code behind. example:
<EditMode>
ColumnA ColumnB
Row I: RadComboBox RadComboBox
Row II: RadNumericTextBox RadNumericTextBox
Row III: CheckBox CheckBox
...
The problem is the Rad-grid Batch mode only have one Control in one Edit-template for each column, that means all the rows have the same Edit-template and control.
this I can Do
ColumnA (RadComboBox) ColumnB(RadNumericTextBox)
Row I: RadComboBox RadNumericTextBox
Row II: RadComboBox RadNumericTextBox
Row III: RadComboBox RadNumericTextBox
Is it possible to have Multiple Edit-templates per column or what is my alternatives?
You can add controls to a cell in the grid's ItemDataBound event. In my example below, I change the cell's contents to the control type you listed instead of just showing its default text ID. You can do the same based on whatever your condition is. I populate the example grid with test data in the rgTest_OnNeedDataSource
method and then apply the changes in the rgTest_ItemDataBound
method.
aspx:
<telerik:RadGrid ID="rgTest" runat="server" PageSize="10" GridLines="None" AccessKey="0" Skin="Office2007"
OnNeedDataSource="rgTest_OnNeedDataSource" OnItemDataBound="rgTest_ItemDataBound" AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" ImagesPath="~/Skins/Office2007/Grid/Images">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn UniqueName="ID" DataField="ID" SortExpression="ID" HeaderText="ID" HeaderStyle-Width="40px" FilterControlWidth="40px" AllowSorting="true" AllowFiltering="true" AutoPostBackOnFilter="false" ShowFilterIcon="true" />
<telerik:GridBoundColumn UniqueName="Value" DataField="Value" SortExpression="Value" HeaderText="Value" HeaderStyle-Width="80px" FilterControlWidth="40px" AllowSorting="true" AllowFiltering="true" AutoPostBackOnFilter="false" ShowFilterIcon="true" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
aspx.cs:
protected void rgTest_OnNeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
DataTable batchChecks = new DataTable("checksRandomName");
batchChecks.Columns.Add("ID");
batchChecks.Columns.Add("Value");
batchChecks.Rows.Add(new ArrayList() { "1", "ABC" }.ToArray());
batchChecks.Rows.Add(new ArrayList() { "2", "BCD" }.ToArray());
batchChecks.Rows.Add(new ArrayList() { "3", "CDE" }.ToArray());
batchChecks.Rows.Add(new ArrayList() { "4", "DEF" }.ToArray());
DataSet dsBatch = new DataSet("rcBatch");
dsBatch.Tables.Add(batchChecks);
rgTest.VirtualItemCount = dsBatch.Tables.Count;
rgTest.DataSource = dsBatch;
}
protected void rgTest_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
TableCell cell = item["Id"];
switch (cell.Text)
{
case "1":
cell.Controls.Add(new RadComboBox());
break;
case "2":
cell.Controls.Add(new RadNumericTextBox());
break;
case "3":
cell.Controls.Add(new System.Web.UI.WebControls.CheckBox());
break;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.