
Santaji Garwe
Top achievements
Rank 1
Santaji Garwe
asked on 26 Jun 2008, 02:28 PM
hi want to add rad controls dynamically in rad grid .After clicking edit dependin on the value of category id row should have checkbox,drop down,textbox
category id =0 -->checkbox
category id =1 -->dropdown
category id=2-->textbox
following is th aspx code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RadCont.ascx.cs" Inherits="RadCont" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<table id="Tab">
<tr>
<td>
<asp:SqlDataSource
ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CAAConnectionString %>"
SelectCommand="SELECT [name] FROM [record_status]">
</asp:SqlDataSource>
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False" runat="server" GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound">
<MasterTableView DataKeyNames="CategoryId">
<DetailTables>
<telerik:GridTableView DataKeyNames="ParameterVal" Name="Value">
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridBoundColumn SortExpression="Name" HeaderText="Name" DataField="Name" HeaderButtonType="TextButton" UniqueName="ShortName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CategoryId" HeaderText="Id" DataField="CategoryId" HeaderButtonType="TextButton" Visible="False" Display="False" UniqueName="CategoryId"></telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="Description" HeaderText="Description" DataField="Description" HeaderButtonType="TextButton" UniqueName="Description"></telerik:GridBoundColumn>
<telerik:GridEditCommandColumn UniqueName="EditCol">
</telerik:GridEditCommandColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<EditColumn UniqueName="EditCol">
</EditColumn>
<FormTemplate>
<table id="Table1">
<tr>
</tr>
</table>
</FormTemplate>
<PopUpSettings ScrollBars="None" />
</EditFormSettings>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
</MasterTableView>
<ClientSettings AllowColumnsReorder="True">
</ClientSettings>
</telerik:RadGrid>
</td>
</tr>
</table>
category id =0 -->checkbox
category id =1 -->dropdown
category id=2-->textbox
following is th aspx code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RadCont.ascx.cs" Inherits="RadCont" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<table id="Tab">
<tr>
<td>
<asp:SqlDataSource
ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CAAConnectionString %>"
SelectCommand="SELECT [name] FROM [record_status]">
</asp:SqlDataSource>
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False" runat="server" GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound">
<MasterTableView DataKeyNames="CategoryId">
<DetailTables>
<telerik:GridTableView DataKeyNames="ParameterVal" Name="Value">
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridBoundColumn SortExpression="Name" HeaderText="Name" DataField="Name" HeaderButtonType="TextButton" UniqueName="ShortName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CategoryId" HeaderText="Id" DataField="CategoryId" HeaderButtonType="TextButton" Visible="False" Display="False" UniqueName="CategoryId"></telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="Description" HeaderText="Description" DataField="Description" HeaderButtonType="TextButton" UniqueName="Description"></telerik:GridBoundColumn>
<telerik:GridEditCommandColumn UniqueName="EditCol">
</telerik:GridEditCommandColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<EditColumn UniqueName="EditCol">
</EditColumn>
<FormTemplate>
<table id="Table1">
<tr>
</tr>
</table>
</FormTemplate>
<PopUpSettings ScrollBars="None" />
</EditFormSettings>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
</MasterTableView>
<ClientSettings AllowColumnsReorder="True">
</ClientSettings>
</telerik:RadGrid>
</td>
</tr>
</table>
10 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 27 Jun 2008, 07:29 AM
Hi ,
Try the following code snippet to achieve the desired scenario.
CS:
Thanks
Princy.
Try the following code snippet to achieve the desired scenario.
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) |
{ |
GridEditableItem edititem = (GridEditableItem)e.Item; |
string strtxt = edititem.GetDataKeyValue("CategoryId").ToString(); |
if (strtxt == "0") |
{ |
edititem["CategoryId"].Controls.Clear(); |
CheckBox chkbx = new CheckBox(); |
chkbx.ID = "CheckBox1"; |
edititem["CategoryId"].Controls.Add(chkbx); |
} |
else if (strtxt == "1") |
{ |
edititem["CategoryId"].Controls.Clear(); |
DropDownList ddl = new DropDownList(); |
ddl.ID = "DropDownList1"; |
edititem["CategoryId"].Controls.Add(ddl); |
} |
else if (strtxt == "2") |
{ |
edititem["CategoryId"].Controls.Clear(); |
TextBox txtbx = new TextBox(); |
txtbx.ID = "TextBox1"; |
edititem["CategoryId"].Controls.Add(txtbx); |
} |
} |
} |
Thanks
Princy.
0

Santaji Garwe
Top achievements
Rank 1
answered on 27 Jun 2008, 10:11 AM
hi
i have tried ur method for adding just one control but wasnt successful after adding the control couldn't find it please see the code below
and though for first if condition item has to be GridEditableItem
but it still entered in the first loop
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
{
GridEditableItem geItem = (GridEditableItem)e.Item;
geItem["Value"].Controls.Clear();
DropDownList DD = new DropDownList();
DD.ID = "DrpList";
geItem["Value"].Controls.Add(DD);
}
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem editform = (GridEditFormItem)e.Item;
DropDownList ddl = (DropDownList)editform.FindControl("DrpList");
ddl.DataSource = AvailableRecordStatusList.GetStatusList();
ddl.DataTextField = "value";
ddl.DataValueField = "key";
ddl.DataBind();
}
}
i have tried ur method for adding just one control but wasnt successful after adding the control couldn't find it please see the code below
and though for first if condition item has to be GridEditableItem
but it still entered in the first loop
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
{
GridEditableItem geItem = (GridEditableItem)e.Item;
geItem["Value"].Controls.Clear();
DropDownList DD = new DropDownList();
DD.ID = "DrpList";
geItem["Value"].Controls.Add(DD);
}
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem editform = (GridEditFormItem)e.Item;
DropDownList ddl = (DropDownList)editform.FindControl("DrpList");
ddl.DataSource = AvailableRecordStatusList.GetStatusList();
ddl.DataTextField = "value";
ddl.DataValueField = "key";
ddl.DataBind();
}
}
0

Shinu
Top achievements
Rank 2
answered on 27 Jun 2008, 11:11 AM
Hi Santaji,
Try accesing the control added in edit form in PreRender event as shown below.
CS:
Thanks
Shinu.
Try accesing the control added in edit form in PreRender event as shown below.
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridEditFormItem item in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)) |
{ |
if (item.IsInEditMode) |
{ |
DropDownList DDL = (DropDownList)item["CategoryID"].FindControl("DrpLis"); |
} |
} |
} |
Thanks
Shinu.
0

Santaji Garwe
Top achievements
Rank 1
answered on 27 Jun 2008, 12:02 PM
sorry actually i missed telling u that my edit form in detail table view so i am not able to access the item in pre render event
please help
Thanks
please help
Thanks
0

Collin
Top achievements
Rank 1
answered on 22 Oct 2008, 10:30 PM
No reply Santaji?
0
Hello Santaji,
The same event is raised for the detail table as well, so the same logic is applicable.
If you are not able to get the elements, and the issue persists, you can open a formal support ticket, and send us the code for further review.
Kind regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
The same event is raised for the detail table as well, so the same logic is applicable.
If you are not able to get the elements, and the issue persists, you can open a formal support ticket, and send us the code for further review.
Kind regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

JJ
Top achievements
Rank 2
answered on 21 Jul 2014, 03:53 PM
I build columns and controls dynamically successful. But on save the controls cannot be find in code-behind. Why?
0

Princy
Top achievements
Rank 2
answered on 22 Jul 2014, 04:51 AM
Hi JJ,
I'm not clear about your scenario. Can you please elaborate on your requirement. How are you saving the Grid values and how you are accessing them, provide you code snippet as well for more help.
Thanks,
Princy
I'm not clear about your scenario. Can you please elaborate on your requirement. How are you saving the Grid values and how you are accessing them, provide you code snippet as well for more help.
Thanks,
Princy
0

JJ
Top achievements
Rank 2
answered on 22 Jul 2014, 06:49 AM
Hi
see this post for more details:
http://www.telerik.com/forums/dynamically-created-textbox-in-radgrid#oFguiPXN_E6wSjfQ2fL4QQ
see this post for more details:
http://www.telerik.com/forums/dynamically-created-textbox-in-radgrid#oFguiPXN_E6wSjfQ2fL4QQ
0

Gajanan
Top achievements
Rank 2
answered on 17 Aug 2015, 10:04 AM
Dear all,
My requirement is Bind the grid dynamic , and add the controls like Text Box And rad Como box at run time by Item value.
so far have done the control adding and now my grid is ready to take values from user ,
but when user selected value from rad combo box (dynamic added control in grid), and click the save button i cannot find the Rad Combo box
pls suggest me the way how to get the values for dynamically added controls in Rad-grid on button click.
below are the steps i followed
1. Added Grid in Aspx. with Autogenerated Column = true
2. On Item created event added dynamic controls in Grid.
3. bind the data to ad combo box (dynamic added control in grid)
4. on save Button i have to save the selected values from rad combo box (dynamic added control in grid), to data base
in above step 1 to 3 are done , but step 4 making me trouble .
below is code for button click.
protected void btnSaveAll_Click(object sender, EventArgs e)
{
Questionnaire MyQue = Questionnaire.getQuestionnaire(mQuestionnaireid);
ArrayList ColumnLst = GetColumnList();
Dictionary<string,string> RowSplitValue = new Dictionary<string,string>();
foreach (GridEditableItem Item in rgPivotQuestionnaireResult.MasterTableView.Items)
{
foreach (GridColumn Column in rgPivotQuestionnaireResult.MasterTableView.RenderColumns)
{
if (ColumnLst.Contains(Column.UniqueName))
{
//RowSplitValue = new Dictionary<string, string>(Item.SavedOldValues[Column.UniqueName]);
if (Item[Column].Controls.Count > 0)
{
Control ItemControle= new Control();
ItemControle = Item[Column].Controls[0];
if (ItemControle is TextBox)
{
TextBox TxtBx = (TextBox)Item[Column].Controls[0];
}
if (Item[Column].Controls.Count > 1)
{
ItemControle = Item[Column].Controls[1];
if (ItemControle is RadComboBox)
{
RadComboBox RCB = (RadComboBox)Item[Column].Controls[1];
MyQue .Answervalue = RCB.SelectedValue;
}
}
}
}
}
}
MyQue .Save();
}
My requirement is Bind the grid dynamic , and add the controls like Text Box And rad Como box at run time by Item value.
so far have done the control adding and now my grid is ready to take values from user ,
but when user selected value from rad combo box (dynamic added control in grid), and click the save button i cannot find the Rad Combo box
pls suggest me the way how to get the values for dynamically added controls in Rad-grid on button click.
below are the steps i followed
1. Added Grid in Aspx. with Autogenerated Column = true
2. On Item created event added dynamic controls in Grid.
3. bind the data to ad combo box (dynamic added control in grid)
4. on save Button i have to save the selected values from rad combo box (dynamic added control in grid), to data base
in above step 1 to 3 are done , but step 4 making me trouble .
below is code for button click.
protected void btnSaveAll_Click(object sender, EventArgs e)
{
Questionnaire MyQue = Questionnaire.getQuestionnaire(mQuestionnaireid);
ArrayList ColumnLst = GetColumnList();
Dictionary<string,string> RowSplitValue = new Dictionary<string,string>();
foreach (GridEditableItem Item in rgPivotQuestionnaireResult.MasterTableView.Items)
{
foreach (GridColumn Column in rgPivotQuestionnaireResult.MasterTableView.RenderColumns)
{
if (ColumnLst.Contains(Column.UniqueName))
{
//RowSplitValue = new Dictionary<string, string>(Item.SavedOldValues[Column.UniqueName]);
if (Item[Column].Controls.Count > 0)
{
Control ItemControle= new Control();
ItemControle = Item[Column].Controls[0];
if (ItemControle is TextBox)
{
TextBox TxtBx = (TextBox)Item[Column].Controls[0];
}
if (Item[Column].Controls.Count > 1)
{
ItemControle = Item[Column].Controls[1];
if (ItemControle is RadComboBox)
{
RadComboBox RCB = (RadComboBox)Item[Column].Controls[1];
MyQue .Answervalue = RCB.SelectedValue;
}
}
}
}
}
}
MyQue .Save();
}