This is a migrated thread and some comments may be shown as answers.

How to populate a drop down list dynamically, when the row is selected for insert

14 Answers 1028 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ivo
Top achievements
Rank 1
Ivo asked on 29 Feb 2008, 04:18 AM

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

Sort by
0
Vlad
Telerik team
answered on 29 Feb 2008, 08:58 AM
Hi Ivo,

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
0
Ivo
Top achievements
Rank 1
answered on 29 Feb 2008, 01:49 PM

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

0
Vlad
Telerik team
answered on 29 Feb 2008, 01:51 PM
Hi 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
0
Ivo
Top achievements
Rank 1
answered on 29 Feb 2008, 05:01 PM

 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

0
Vlad
Telerik team
answered on 04 Mar 2008, 09:41 AM
Hello 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
0
al
Top achievements
Rank 1
answered on 17 Apr 2008, 12:18 PM
When you have populated the combo box dynamically, how do you set the selected index to it corresponding value in the grid?
0
Vlad
Telerik team
answered on 18 Apr 2008, 07:18 AM
Hi al,

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
0
newbie
Top achievements
Rank 1
answered on 22 Apr 2008, 05:22 PM
I tried binding the selectedvalue but it gives me an error that Bind() can be used only with a boundcontrol./
I am populating my dropdown from code behind.

Is there something I am doing wrong?
0
Juan
Top achievements
Rank 1
answered on 08 Jun 2008, 09:56 PM
I also filled the combo but getting the same error, can I bind the combo box to the field after it is filled in the itemcreated event ?
Thank you
Juan
0
Yavor
Telerik team
answered on 09 Jun 2008, 05:37 AM
Hello 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
0
John Davis
Top achievements
Rank 2
answered on 16 Nov 2009, 02:20 PM

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).

0
Sebastian
Telerik team
answered on 16 Nov 2009, 03:03 PM
Hello John,

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.
0
John Davis
Top achievements
Rank 2
answered on 17 Nov 2009, 03:54 AM
Sebastian

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
0
Sebastian
Telerik team
answered on 17 Nov 2009, 09:39 AM
Hello 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.
Tags
Grid
Asked by
Ivo
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Ivo
Top achievements
Rank 1
al
Top achievements
Rank 1
newbie
Top achievements
Rank 1
Juan
Top achievements
Rank 1
Yavor
Telerik team
John Davis
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or