DropDownList in Datagrid

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?
 
B

bill

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.
 
A

alex bowers

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top