DropDownList in Datagrid

Discussion in 'ASP .Net' started by Sid, Nov 10, 2003.

  1. Sid

    Sid Guest

    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?
    Sid, Nov 10, 2003
    #1
    1. Advertising

  2. Sid

    bill Guest

    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 wrote:

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


    --
    bill
    e-mail:
    MSN Messenger:
    Web: http://www.minivoice.com
    bill, Nov 10, 2003
    #2
    1. Advertising

  3. Sid

    alex bowers Guest

    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

    >-----Original Message-----
    >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?
    >.
    >
    alex bowers, Nov 10, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,574
    mr2_93
    Oct 2, 2005
  2. tshad
    Replies:
    8
    Views:
    2,199
    tshad
    Oct 19, 2005
  3. =?Utf-8?B?SnVhbmpv?=

    GridView: Filtr DropDownList from another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,842
    =?Utf-8?B?SnVhbmpv?=
    Dec 23, 2005
  4. =?Utf-8?B?SnVhbmpv?=

    GridView: Filter DropDownList for another DropDownList

    =?Utf-8?B?SnVhbmpv?=, Dec 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,275
    =?Utf-8?B?SnVhbmpv?=
    Dec 29, 2005
  5. keithb
    Replies:
    1
    Views:
    11,896
    shauns1
    Nov 1, 2006
Loading...

Share This Page