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

Dynamic Dropdown in Rad Grid(In ASP.Net with C#)

1 Answer 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexis
Top achievements
Rank 1
Alexis asked on 22 Feb 2011, 09:06 AM
Hi Team,
               I'm using Rad Grid in my application. I need to show my grid as follows. 

Source Column

Lookup Column

Filter Condition

Action

This is Drop down (Dynamic values)

This is Dropdown  (Dynamic values)

This is (static values) Drop down

Edit

This is Dropdown (Dynamic values)

This is Dropdown  (Dynamic values)

This is (static values) Drop down

Edit

This is Drop down (Dynamic values)

This is Dropdown  (Dynamic values)

This is (static values) Drop down

Edit

This is Dropdown (Dynamic values)

This is Dropdown  (Dynamic values)

This is (static values) Drop down

Edit


Each Dynamic Dropdown has different set of values.
aspx coding:

<telerik:RadGrid runat="server" ID="GridRelateColumn" GridLines="None" Skin="Outlook"

AllowPaging="true" PageSize="10" OnItemDataBound="GridRelateColumn_ItemDataBound"

AutoGenerateColumns="False">

<mastertableview>

<Columns>                                                                                         

      <telerik:GridTemplateColumn headertext="Source Columns" uniquename="SourceColumn">

           <itemtemplate>                                                                                                 

<asp:DropDownList ID="SourceDropDownList" runat="server” Width="160px"></asp:DropDownList>

</itemtemplate>

                                                                                        </telerik:GridTemplateColumn>                                                                                        <telerik:GridTemplateColumn headertext="LookUp Columns" uniquename="LookUpColumns">

<itemtemplate>                                                                                                          <asp:DropDownList ID="LookUpDropDownList" Width ="160px"  runat="server"></asp:DropDownList>

</itemtemplate>

</telerik:GridTemplateColumn>

     <telerik:GridTemplateColumn UniqueName="FilterCondition" HeaderText="Filter Condition">

<itemtemplate>                                                                                                 <asp:DropDownList runat="server" Width ="160px" ID="ddlApplicationStatus"></asp:DropDownList>

</itemtemplate>                                                                                        </telerik:GridTemplateColumn>                                                                                        <telerik:GridEditCommandColumn HeaderText="Action" UniqueName="EditCommandColumn" />

</Columns>

</mastertableview>

</telerik:RadGrid>


Codebehind coding:

protected void GridRelateColumn_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                DataTable dtDDList = new DataTable();
                DataTable dttest = new DataTable();
                string definitionID = string.Empty;

                GridDataItem item = (GridDataItem)e.Item;
                dttest = (DataTable)item.OwnerTableView.DataSource;

                for (int i = 0; i < dttest.Rows.Count; i++)
                {
                    definitionID = dttest.Rows[i]["Source Column"].ToString();
                    if (definitionID != "" && definitionID != "1")
                    {
                        DropDownList dDownList = (DropDownList)item.FindControl("SourceDropDownList");
                        dtDDList = (DataTable)BLogic.BusinessComponents.RelateColumn.getAllColumnsByDefinitionID(new Guid(definitionID), new Guid(Session["ProjectID"].ToString()));
                        dDownList.DataSource = dtDDList;
                        dDownList.DataTextField = "ColumnName";
                        dDownList.DataValueField = "Selected_Column_GUID";
                        dDownList.DataBind();
                    }
                }
                for (int j = 0; j < dttest.Rows.Count; j++)
                {
                    definitionID = dttest.Rows[j]["Lookup Column"].ToString();
                    if (definitionID != "" && definitionID != "1")
                    {
                        DropDownList dDownList = (DropDownList)item.FindControl("LookUpDropDownList");
                        dtDDList = (DataTable)BLogic.BusinessComponents.RelateColumn.getAllColumnsByDefinitionID(new Guid(definitionID), new Guid(Session["ProjectID"].ToString()));
                        dDownList.DataSource = dtDDList;
                        dDownList.DataTextField = "ColumnName";
                        dDownList.DataValueField = "Selected_Column_GUID";
                        dDownList.DataBind();
                    }
                }
            }
        } 

For Example (please have a look at the below grid)

Source Column

Lookup Column

Filter Condition

Action

This drop down will show states of US

This drop down will show states of Europe

This drop down will shows years.(static data)

Edit

This drop down will show states of Brazil

This drop down will show states of India

This drop down will shows years.(static data)

Edit

This drop down will show states of Canada

This drop down will show states of Russia

This drop down will shows years.(static data)

Edit

This drop down will show states of China

This drop down will show states of Germany

This drop down will shows years.(static data)

Edit




Please help us as soon as possible. we need the solution or suggestion urgently.



Thanks
Alexis.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 25 Feb 2011, 10:18 AM
Hello Alexis,

The approach you have taken is generally correct. What is the issue you are having exactly?

Veli
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Alexis
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or