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

[Solved] Binding items to a Dynamically generated GridDropDownColumn

8 Answers 371 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ketan reddy
Top achievements
Rank 1
ketan reddy asked on 17 Apr 2009, 02:48 PM
Hi,

I am having problems with populating a dynamically created GridDropDownColumn.  It is not getting populated.

I am doing everything from the codebehind. I am creating a Grid. then adding columns-Checkbox, dropdowns and textboxes.

case 12:  // Implies DropDownList Column
                                dropDownColumn = new GridDropDownColumn();                              
                                dropDownColumn.HeaderText = ListTableColumn[varLoop].Title;
                                dropDownColumn.DataField = ListTableColumn[varLoop].ColumnName;
                           //     dropDownColumn.DataSourceID = "SqlDataSource1";
                                dropDownColumn.ListTextField = ListTableColumn[varLoop].ColumnName;
                                dropDownColumn.ListValueField = ListTableColumn[varLoop].ColumnName;                     
                                dropDownColumn.UniqueName = ListTableColumn[varLoop].ColumnName;
                               grdMain.MasterTableView.Columns.Add(dropDownColumn);


Though the GridBoundColumn and the GridCheckBoxColumn get populated, the dropdown column shows me an empty column. Even when i get into the edit mode, the dropdown does not have any values.
Do I need to use an ItemDataBound event handler? I tried this but was not sucessfull.

Can someone please help me with this?

Thanks.


8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Apr 2009, 07:38 AM
Hi Ketan,

From the above given code it seems that you have commented out the line which sets the DataSourceID for the GridDropDownColumn. Try setting the DataSourceID for the GridDropDownColumn and see whether it works. Here is the code which I tried on my end.

CS:
 
   RadGrid grid = new RadGrid(); 
    .... 
 
  GridDropDownColumn DropCol = new GridDropDownColumn(); 
  DropCol.HeaderText = "ProductName"
  DropCol.DataField = "ProductName"
  DropCol.DataSourceID = "SqlDataSource1"
  DropCol.ListTextField = "ProductName"
  DropCol.ListValueField = "ProductName"
  DropCol.UniqueName = "DropCol"
 
  grid.MasterTableView.Columns.Add(DropCol); 
 


Thanks
Shinu
0
ketan reddy
Top achievements
Rank 1
answered on 20 Apr 2009, 01:28 PM
Thanks for the response. I did try with the data source Id too. But still the dropdownlist column comes up empty.

-Ketan Reddy
0
Shinu
Top achievements
Rank 2
answered on 21 Apr 2009, 04:30 AM
Hi Ketan,

The above given code was working fine on my end. Can you confirm that the field that you have set as the DataField,ListTextField and ListValueField does exist in the DataSource that you have assigned for the GridDropDownColumn.

Shinu.
0
ketan reddy
Top achievements
Rank 1
answered on 21 Apr 2009, 02:38 PM
Hi Shinu,

I checked again with different data but of no use. The dropdown column still comes up empty. The DataField,ListTextField and ListValueField  values do exist in the datasource. It should be a fairly straightforward thing to do ...... Is there something else I might be missing?

Thanks,
Ketan Reddy
0
Tsvetoslav
Telerik team
answered on 22 Apr 2009, 09:43 AM
Hello ketan,

Could you post your complete code behind - please, use the Code Block Formatter of the html editor when pasting the code.

Thank you.

Looking forward to your feedback.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ketan reddy
Top achievements
Rank 1
answered on 27 Apr 2009, 07:55 PM
Allright....I found my mistake. When I tried with a "sqldatasourceId" and set the  griddropdown datasource id, it worked.

I had been doing the following where dsTableDetails2 is a SqlDataAdapter. How do I assign data from a dataAdapter to the griddropdown?

 

dropDownColumn.HeaderText = "StateOrProvinceId";  
 
dropDownColumn.DataField = "StateOrProvinceId";  
 
dropDownColumn.ListTextField = "Title";  
 
dropDownColumn.ListValueField = "StateOrProvinceId";  
 
dropDownColumn.DataSourceID = "dsTableDetails2";  //This is the SQLdataAdaptor  
 
dropDownColumn.UniqueName = "dropDownColumn";  
 

 

    SqlConnection con2 = new SqlConnection(ConnString);  
                    con2.Open();  
                    string sqlString2 = "SELECT StateOrProvinceId, Title FROM City";  
                    dsTableDetails2 = new DataSet();  
                    adapter2 = new SqlDataAdapter();  
                    adapter2.SelectCommand = new SqlCommand(sqlString2, con2);  
                    adapter2.Fill(dsTableDetails2,"City"); 

Thanks.

 

 

 

0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Apr 2009, 05:45 AM
Hi Ketan,

  Try setting the ListDataMember property of the GridDropDownColumn to City. You can refer the following help article to get more details on configuring GridDropDownColumn.
Customize/Configure GridDropDownColumn

Thanks
Shinu

0
ketan reddy
Top achievements
Rank 1
answered on 28 Apr 2009, 06:03 PM
Thanks...sorry for the trouble!
Tags
Grid
Asked by
ketan reddy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ketan reddy
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or