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

2 posts, 0 answers
  1. Alexis
    Alexis avatar
    23 posts
    Member since:
    Aug 2010

    Posted 22 Feb 2011 Link to this post

    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.

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 25 Feb 2011 Link to this post

    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!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top