Hello,
I want to populate a drop down control, included as EditItemTemplate in a Prometheus grid, dynamically when the row is selected for insert -radGrid.InitInsertCommandName.
I was trying to use grdGDS_ItemCommand and to cast GridTemplateColumn to drop down list control, but it doesn’t allow me to do this.
I would like to ask if there is a way to accomplish this.
Also, I would like to ask if the following code
currentRow.Item.OwnerTableView.ExtractValuesFromItem(valueHash, currentRow.Item)
works for controls in EditItemTemplate and gets their values.
Thanks,
Ivo
14 Answers, 1 is accepted
ItemCommand is too early to the get the controls from the edit form. You can use ItemCreated instead. Here is an example:
if(e.Item is GridEditableItem && e.Item.IsInEditMode) // will work in edit and insert
{
DropDownList DropDownList1 = (DropDownList)e.Item.FindControl("DropDownListID");
}
There are no differences with ExtractValuesFromItem() related to different edit modes.
Best wishes,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

Hi Vlad,
Thank you for the quick response.
Yes, I can get the control and to pupluate it dynamically in ItemCreated, but I need also to separate Insert from Edit mode. In my case, In Edit only mode the control should be read only and available for selection only in InitInsert.
I may try to use an extra flag on the page and to get the status from ItemCommand and to check in ItemCreated, but I am wondering if there is a direct way to do this in the ItemCreated event itself.
In general, I would like to have a grid column as read only in Edit mode and available as drop down selection in Insert mode, but with options dynamically created when a user clicks on Insert record.
Thanks,
Ivo
Here is an example:
if(e.Item is GridEditFormItem && e.Item.IsInEditMode) // edit
{
//
}
if(e.Item is GridEditFormInsertItem) // insert
{
//
}
Regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

Hi Vlad,
Unfortunately the code above doesn’t work and the row never comes as GridEditFormItem or GridEditFormInsertItem. It comes as GridEditableItem, but I can’t separate between Insert and Edit mode.
Here is the aspx part of the Template column. Am I missing something?
<telerik:GridTemplateColumn HeaderText="Brand"
UniqueName="Brand">
<EditItemTemplate>
<asp:DropDownList id="ddlBrnd" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label id="lblBrnd" runat="server" Text='<%# Eval("BrandID") %>'>
</asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
Thanks,
Ivo
If you use InPlace edit mode you can do:
if(e.Item is GridDataItem && e.Item.IsInEditMode) // edit
{
//
}
if(e.Item is GridDataInsertItem) // insert
{
//
}
Greetings,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

You can use directly Bind() to set SelectedValue no matter if the combo is populated dynamically or not:
<asp:DropDownList ID="ddlTOC" runat="server" SelectedValue='<%# Bind("TitleOfCourtesy") %>' ...
You can check this example for more info:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx
Regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

I am populating my dropdown from code behind.
Is there something I am doing wrong?

Thank you
Juan
You can use the bind expression, as shown in the example posted previously:
.aspx
<asp:DropDownList ID="ddlTOC" runat="server" |
SelectedValue='<%# Bind("TitleOfCourtesy") %>' DataSource='<%# (new string[] { "Dr.", "Mr.", "Mrs.", "Ms." }) %>' TabIndex="7" AppendDataBoundItems="True"> |
Additionally, you can bind the control dynamically, using the ItemDataBound event handler, getting a reference to the combo/dropdown, and setting its datasource in this event.
Regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

How do you populate a drop down list in a user control edit form? Specifically, how did you do it in this demo?
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx
EmployeeDetailsCS.aspx has:
<asp:dropdownlist id="ddlTOC" runat="server" tabindex="7"></asp:dropdownlist></td>
But I did not find the code that loads it with data. I did not see a reference to ddlTOC in the code-behind (DefaultVB.aspx.vb).
Examine the EmployeeDetailsCS.ascx.cs file from the code viewer of the demo and the OnDataBinding server event of the user control in particular. To convert the code to VB.NET language, use our free online converter.
Best regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

Are you sure the EmployeeDetailsCS.ascx.cs file is availble at the demo web site? I did not see it, although EmployeeDetailsCS.ascx is available.
John
If you click the arrow beside the DefaultCS.aspx.cs tab in the code viewer you should be able to see the user control code-behind as an option in the menu that will be displayed.
Regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.