View Full Version : ASP.NET: Data Bound Combo Box In A Data Grid

10-14-2003, 03:33 PM
Would anyone be able to tell me how to do the following:

I have a couple of tables with information. I will get the data needed and bind this to a datagrid or something to display the data. Thats the easy part. Now i have another table, and for each record in the datagrid, there are a couple of records i need to put in a drop down box. So each item in the datagrid will have its own drop down combo box with diffirent data in it...

What is the best way to bind the data to the corresponding drop down boxes?

10-15-2003, 07:29 AM
I've used code similar to the following, with this in the .aspx file:

<asp:DropDownList ... DataSource='<%# GetList() %>' DataTextField="COL1" DataValueField="COL2"></asp:DropDownList>

and in your code behind:

public ICollection GetList()
SqlConnection conn = new SqlConnection("...");
SqlDataAdapter da = new SqlDataAdapter("select COL1, COL2 from ...", conn);
DataSet ds = new DataSet();
return ds.Tables[0].DefaultView;

You can find more DataGrid examples at http://www.codeproject.com/aspnet/datagriddemo.asp

10-15-2003, 07:52 AM
Thanx BrainJar! Thats exactly what I needed... :thumbsup: