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

Programatically setting DropDownList inside EditItemTemplate upon clicking Add New Record

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Richard asked on 26 Mar 2009, 10:02 AM
Hello

I have a DropDownList (DDL) which is also databound to a collection of data inside an EditItemTemplate.
When I click Add New Record, I need to set the DDL selectedValue to specifically.  I have read through http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html but I am having problems finding the DDL control progmatically.  Am I doing this the wrong way round or am I missing something in code please?

Thank you
R


 

<telerik:GridTemplateColumn HeaderText="Group" UniqueName="tcGroup">

 

 

<EditItemTemplate>

 

 

<asp:DropDownList ID="ddlGroupID" runat="server" DataSourceID="sdsVL_Groups" DataTextField="GroupID"

 

 

DataValueField="Name" SelectedValue='<%# Bind("GroupID_FK") %>' AppendDataBoundItems="true" >

 

 

<asp:ListItem Text ="" Value=""></asp:ListItem>

 

 

</asp:DropDownList>

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Mar 2009, 11:56 AM
Hello  Richard,

You can access the DropDownList in the EditItemTemplate of the TemplateColumn in the ItemDataBound as shown below:
c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem editItem = (GridEditFormInsertItem)e.Item; 
            DropDownList ddl = (DropDownList)editItem.FindControl("ddlGroupID");            
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Richard
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or