DropDownList in Datagrid

  • Thread starter Thread starter Sid
  • Start date Start date
S

Sid

Hi All,

I am trying to populate a dropdown list in my Datagrid
control using the OleDbDataReader, but when my function
tries to add items to the dropdownlist it says that my
dropdownlist control has not been 'declared' even though
it is set to runat="server" .

Any ideas?
 
I think you should use data binding to add items to dropdownlist

<asp:DropDownList id=level_DropDownList runat="server" Width="90px"
DataSource="<%# your_function() %>" ></asp:DropDownList>

dropdownlist will bind to the function return value, the function can
return a dataset, array, etc.

Or you can use DataGrid.FindControl("Dropdownlist") to get the instance
of the dropdownlist.
 
Sid,
when you add controls to a datagrid you can't access them
programmatically by referring to their IDs directly.
At run time you can access the control by first
retrieving it from the datagrid cell.
A good time to do this is within the item_databound or
the item_created events of the datagrid; see the
following code example:

[C#]
private void onItemCreated(object
sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DropDownList c =
(DropDownList)e.Item.Cell[0].Controls[0];
c.DataSource = yourdatareader;
//etc
}

regards,
alex
 
Back
Top