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

Referencing and uniquely identifying DropDownLists per row

5 Answers 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CBARS
Top achievements
Rank 2
CBARS asked on 20 Oct 2008, 01:48 PM
Hi

I'm dynamically creating an empty DataTable, with a number of predefined rows. I bind that to a RadGrid control, with one GridDropDownColumn set up. I then make the whole RadGrid editable.

A user will select a value in each of the DropDownLists, and then it will be saved to a database.

However, each DropDownList needs to be bound to a different datasource. How can I uniquely identify each DropDownList?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Oct 2008, 04:41 AM
Hi,

You can get the DataKeyValue for each row on editing and then change the datasource of the dropdown based on the DataKeyValue as shown below.
aspx:
 
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound" >  
 <MasterTableView DataKeyNames="ContactName" DataSourceID="SqlDataSource1">  
  
  <Columns>  
   <telerik:GridDropDownColumn DataSourceID="SqlDataSource1" DropDownControlType="DropDownList" HeaderText="Julie" UniqueName="Supplier" ListTextField="SupplierID" ListValueField="SupplierID" DataField="SupplierID">                 
   </telerik:GridDropDownColumn>  
     ....  
 

cs:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
  
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridEditableItem editItem=(GridEditableItem)e.Item;  
            string strkey = editItem.GetDataKeyValue("ContactName").ToString();  
            if (strkey == "Shelley Burke")  
            {  
                DropDownList ddl = (DropDownList)editItem["Supplier"].Controls[0];  
                // Code to bind the combobox  
            }  
        }  
    }  

Thanks
Princy.
0
CBARS
Top achievements
Rank 2
answered on 21 Oct 2008, 07:46 AM
Hi

Thanks for the approach... I can change the datasource of each row now... However, when you specify a column of type GridDropDownColumn in the RadGrid, it makes a control of type RadComboBox, not DropDownList.

I've filled them like this :

protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridEditableItem editItem = (GridEditableItem)e.Item;  
            string strkey = editItem.GetDataKeyValue("Level").ToString();  
            switch (strkey)  
            {  
                case "Level 1":  
                    DropDownList ddl = (DropDownList)editItem["colIdentifier"].Controls[0];  
                    SqlDataSource sqlds = new SqlDataSource(ConfigurationManager.ConnectionStrings["constring"].ToString(), "Select ID, Identifier ...");  
                    ddl.DataSource = sqlds;  
                    ddl.DataTextField = "Identifier";  
                    ddl.DataValueField = "ID";  
                    ddl.DataBind();  
                    break;  
... 

None of the RadComboBoxes contain any data. I've checked the query, and it does return data. I've made a RadComboBox outside the RadGrid, and it gets filled with the same code, and works fine. Am I doing something wrong?
0
CBARS
Top achievements
Rank 2
answered on 21 Oct 2008, 07:57 AM
I've narrowed the problem down to the DataBind method... After DataBinding, the RadComboBox's DataSource is null. This doesn't happen with my test RadComboBox outside the RadGrid though...
0
CBARS
Top achievements
Rank 2
answered on 23 Oct 2008, 08:51 AM
Any thoughts?
0
Sebastian
Telerik team
answered on 23 Oct 2008, 09:37 AM
Hi cbars,

Basically, there should be no difference whether you use built-in GridDropDownColumn with RadComboBox editor or MS DropDownList editor in it when changing the items in the relevant column editor dynamically. This topic from the documentation illustrates how this can be done (paragraph 'Customizing the options for GridDropDownColumn on editing').

Furthermore, verify that you are using the latest release 2008.2.1001 of RadControls for ASP.NET AJAX in your project.

Kind regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
CBARS
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
CBARS
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or