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

GridDropDownColumn in RadGrid

3 Answers 564 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vinya Veeraraghavan
Top achievements
Rank 1
Vinya Veeraraghavan asked on 30 Sep 2008, 06:07 PM

Hi,

 

I’m trying to bind a GridDropDownColumn dynamically to a RadGrid.

Each row in the RadGrid has an independent GridDropDownColumn and values in these dropdown is not the same in the rest of the rows.

Say, there a row ‘CountyCode’ and has a GridDropDownColumn with a set of CountryCodes.

And the next row may be States and the GridDropDownColumn will have the StatesList.

But when I identify the GridDropDownColumn with a UniqueName, all the dropdown vales in the Grid gets updated with the last set of values.

(Got an example from telerik.com to Customize/Configure GridDropDownColumn)

 

Please let me know how to identify a specific row in a RadGrid & just bind that GridDropDownColumn in that row.

 

Here is the code I’m working on.

 

protected void RadGrid_ItemDataBound (object sender, Telerik.Web.UI.GridItemEventArgs e)

    {

        if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)

        {

            GridEditableItem editedItem = e.Item as GridEditableItem;

            GridEditManager editMan = editedItem.EditManager;

 

            int i = 0;

            foreach (CommonConfigurationDataItem cd in _configData)

            {

                try

                {

                    if (cd.Values != null && cd.Values.Count > 0)

                    {

                        GridDropDownColumnEditor editor = editMan.GetColumnEditor("List") as GridDropDownColumnEditor;

                        editor.DataSource = cd.Values;

                        editor.DataBind();

                    }

                 

                  //’i’ would be a row index – How do I access the GridDropDownColumn in that row using i//

                }

                i++;

            }

 

        }

    }

 

private void AddComboBoxPDValues()

      {

        if (RadGrid.Columns.Contains("List"))

            RadGrid.Columns.Remove("List");

 

        GridDropDownColumn List = new GridDropDownColumn();

        List.HeaderText = "Provisioned Values";

        List.ReadOnly = false;

        List.UniqueName = "List";

        RadGrid.Columns.Add(List);

      }

 

Thanks!

 

Vinya

 

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 03 Oct 2008, 12:45 PM
Hi Vinya,

Let me just clarify:
Do you mean than you have more that one GridDropDownColumn or that you have one GridDropDownColumn?

If you are implementing the first case, then you should have set different UniqueName to each column and use these UniqueNames in the ItemDataBound event handler of the grid to bind the different dropdowns.

If your scenario is like the second case, then you can use the DataKeyNames collection of the MasterTableView to distinguish the different rows.

Below is sample code:

Case 1.)
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
{  
    if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)  
    {  
        GridEditableItem editedItem = e.Item as GridEditableItem;  
        GridEditManager editMan = editedItem.EditManager;  
 
        GridDropDownColumnEditor editor = editMan.GetColumnEditor("CountryCode"as GridDropDownColumnEditor;  
        editor.DataSource = YourCountryCodesDataSource();  
        editor.DataBind();  
 
        editor = editMan.GetColumnEditor("StatesList"as GridDropDownColumnEditor;  
        editor.DataSource = YourStatesListDataSource();  
        editor.DataBind();  
 
    }  
}  
<telerik:RadGrid ID="RadGrid1" runat="server">  
    <MasterTableView>  
        <Columns> 
            <telerik:GridDropDownColumn UniqueName="CountyCode"></telerik:GridDropDownColumn> 
            <telerik:GridDropDownColumn UniqueName="StatesList"></telerik:GridDropDownColumn> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 

Case 2.)
<telerik:RadGrid ID="RadGrid1" runat="server">     
    <MasterTableView DataKeyNames="ID">     
        <Columns>    
            <telerik:GridDropDownColumn UniqueName="DropDownColumn"></telerik:GridDropDownColumn>    
        </Columns>    
    </MasterTableView>    
</telerik:RadGrid>    
 
private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)     
{     
    if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)     
    {     
        GridEditableItem editedItem = e.Item as GridEditableItem;     
        GridEditManager editMan = editedItem.EditManager;     
    
        GridDropDownColumnEditor editor = editMan.GetColumnEditor("DropDownColumn"as GridDropDownColumnEditor;     
        if(((e.Item as GridEditableItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"as int) / 2 == 0)  
        {   
            editor.DataSource = YourCountryCodesDataSource();     
            editor.DataBind();         
        }  
        else 
        {  
            editor.DataSource = YourStatesListDataSource();  
            editor.DataBind();  
        }  
    }     
}     
 


Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vinya Veeraraghavan
Top achievements
Rank 1
answered on 03 Oct 2008, 01:30 PM
Hi Iana, Thanks for your reply!Its one dropdown in the grid but each row would have a different set of values in the dropdown. When I use the UniqueName or the DataKey name, it’s assigned to all the rows for that column in the grid and when updated all the dropdowns in every row is updated with that values in the dropdown. That’s not the one I’m looking for.I need to bind every the dropdown (in each row) dynamically.Say I have 5 rows and each dropdown in these 5 rows have different set of values, NOT THE SAME. Thanks! Vinya
0
Iana Tsolova
Telerik team
answered on 06 Oct 2008, 12:12 PM
Hello Vinya,

Thank you for the details.

I followed your scenario and prepared a sample project for you. Please find it attached and check it out. Let me know if it works as desired and if other issues arise.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Vinya Veeraraghavan
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Vinya Veeraraghavan
Top achievements
Rank 1
Share this question
or