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

Dropdown menu on Edit mode?

3 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 18 May 2011, 09:33 PM
Hi

I have a table that shows the following:

Id     DivisionId     LocationId
-------------------------------------
1      4                  10
2      4                  11
3      4                  12
4      4                  13

The Division Name and Location Name are stored in seperate tables and I can resolve these name easily using linqtosql (see below how i've done this with DivisionName)

<

 

 

Columns>

 

 

<telerik:GridBoundColumn DataField="ID" DataType="System.Int32" HeaderText="ID" UniqueName="ID">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn DataField="Division.DivisionName" HeaderText="DivisionName">

 

 

</telerik:GridBoundColumn>

 

 


<
telerik:GridBoundColumn DataField="LocationID" HeaderText="LocationID">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

 


However, when you click edit/add, i need to be able to show the division names in a dropdown and the user simply selects the option (i also need to do this for location too, but i can replicate this functionality once i know how to do it)

I'm new to linqtosql and the radgrid so please bear that in mind when replying
I've looked at the linqtosql Crud opertations and i'm a little confused.
is there an edit tag, and can i put a dropdown in it and bind it to the division name
if so do you have any example code please?

I've tried using this but it doesn't work

 

 

<EditItemTemplate>

 

 

 

 

<telerik:RadComboBox DataTextField="Division.DivisionName" DataField="Division.DivisionName" ID="ddlDivisionName" runat="server" >

 

 

 

</telerik:RadComboBox>

 

 

 

 

<telerik:RadComboBox DataTextField="Location.LocationName" DataField="Location.LocationName" ID="ddlLocationName" runat="server" >

 

 

 

</telerik:RadComboBox>

 

 

 

</EditItemTemplate>

Thanks!

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 May 2011, 05:30 AM
Hello Markus,

In order to populate DropDownList in edit mode, attach ItemCreated to your RadGrid. Try the following snippet code. Hope this helps you.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
  {
    if (e.Item is  GridEditFormItem && e.Item.IsInEditMode)
      {
        DropDownList dropdown = (e.Item as GridEditFormItem)["TemplateColumnUniqueName"].FindControl("DropDownList1") as DropDownList;
              dropdown.DataSource =
//datasource
        dropdown.DataTextField = //Division.DivisionName
        dropdown.DataBind();
 }
    } 

Also check the following demo which handles CRUD operations using Linq to SQL data context.
Grid / LinqToSql Manual CRUD Operations.

Thanks,
Princy.
0
Mark
Top achievements
Rank 1
answered on 19 May 2011, 09:11 AM
Thanks
I've tried using the example but it fails on this line as its cannot find the control 
DropDownList dropdown = (e.Item as GridEditFormItem)["TemplateColumnUniqueName"].FindControl("DropDownList1") as DropDownList;

I've obviously replaced the names
Do i need the HTML to look a certain way?
i.e. i've used the <EditItemTemplate> i used in my first example

Thanks

0
Accepted
Radoslav
Telerik team
answered on 24 May 2011, 12:45 PM
Hi Markus,

I am sending you a simple example, which demonstrates how to achieve the desired functionality. Please check it out and let me know if it helps you.

Looking forward for your reply.

Best wishes,
Radoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or