DropDownList Datagrid issues

Discussion in 'ASP .Net Datagrid Control' started by msingh.russelmetals@gmail.com, Jun 2, 2006.

  1. Guest

    Hello everybody.

    I have a DropDownList in my Datagrid.
    The DropDownList is prepopulated with data.

    I'm capturing the event OnItemDataBound, and as the rows are populated
    I'm selecting the correct index in my DropDownList based on a value for
    that row.

    My issue is that it seems that instead of selecting the value in the
    DropDownList for that row, it selects the value in all the
    DropDownLists for that column in the entire DataGrid.

    So all the rows have the same value selected in the DropDownList that
    corresponds to the value of the item that was meant for the last row.

    Anybody seen this before and can help me out?

    Thanks in advanced.
    , Jun 2, 2006
    #1
    1. Advertising

  2. DomNewbie Guest

    This is how I do it, though there may be a more elegant solution...

    private void
    DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    //select the data from the datasource
    DataRow[] drs =td.Stock.Select("rowGuide=" +
    e.Item.Cells[2].Text);
    //select the DropDownlist control you're looking at (Control 1 in cell
    10)
    DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
    //set the dropdownlist to reflect the data
    ddl.SelectedValue =drs[0]["InStock"].ToString();

    }

    wrote:

    > Hello everybody.
    >
    > I have a DropDownList in my Datagrid.
    > The DropDownList is prepopulated with data.
    >
    > I'm capturing the event OnItemDataBound, and as the rows are populated
    > I'm selecting the correct index in my DropDownList based on a value for
    > that row.
    >
    > My issue is that it seems that instead of selecting the value in the
    > DropDownList for that row, it selects the value in all the
    > DropDownLists for that column in the entire DataGrid.
    >
    > So all the rows have the same value selected in the DropDownList that
    > corresponds to the value of the item that was meant for the last row.
    >
    > Anybody seen this before and can help me out?
    >
    > Thanks in advanced.
    DomNewbie, Jun 6, 2006
    #2
    1. Advertising

  3. DomNewbie Guest

    This is how I do it, though there may be a more elegant solution...

    private void
    DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    //select the data from the datasource
    DataRow[] drs =td.Stock.Select("rowGuide=" +
    e.Item.Cells[2].Text);
    //select the DropDownlist control you're looking at (Control 1 in cell
    10)
    DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
    //set the dropdownlist to reflect the data
    ddl.SelectedValue =drs[0]["InStock"].ToString();

    }

    wrote:

    > Hello everybody.
    >
    > I have a DropDownList in my Datagrid.
    > The DropDownList is prepopulated with data.
    >
    > I'm capturing the event OnItemDataBound, and as the rows are populated
    > I'm selecting the correct index in my DropDownList based on a value for
    > that row.
    >
    > My issue is that it seems that instead of selecting the value in the
    > DropDownList for that row, it selects the value in all the
    > DropDownLists for that column in the entire DataGrid.
    >
    > So all the rows have the same value selected in the DropDownList that
    > corresponds to the value of the item that was meant for the last row.
    >
    > Anybody seen this before and can help me out?
    >
    > Thanks in advanced.
    DomNewbie, Jun 6, 2006
    #3
  4. DomNewbie Guest

    This is how I do it, though there may be a more elegant solution...

    private void
    DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    //select the data from the datasource
    DataRow[] drs =td.Stock.Select("rowGuide=" +
    e.Item.Cells[2].Text);
    //select the DropDownlist control you're looking at (Control 1 in cell
    10)
    DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
    //set the dropdownlist to reflect the data
    ddl.SelectedValue =drs[0]["InStock"].ToString();

    }

    wrote:

    > Hello everybody.
    >
    > I have a DropDownList in my Datagrid.
    > The DropDownList is prepopulated with data.
    >
    > I'm capturing the event OnItemDataBound, and as the rows are populated
    > I'm selecting the correct index in my DropDownList based on a value for
    > that row.
    >
    > My issue is that it seems that instead of selecting the value in the
    > DropDownList for that row, it selects the value in all the
    > DropDownLists for that column in the entire DataGrid.
    >
    > So all the rows have the same value selected in the DropDownList that
    > corresponds to the value of the item that was meant for the last row.
    >
    > Anybody seen this before and can help me out?
    >
    > Thanks in advanced.
    DomNewbie, Jun 6, 2006
    #4
    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. Shapper

    Asp:DropDownList and Firefox Issues

    Shapper, May 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,303
    Bruce Barker
    May 19, 2005
  2. mr2_93
    Replies:
    1
    Views:
    3,593
    mr2_93
    Oct 2, 2005
  3. tshad
    Replies:
    8
    Views:
    2,224
    tshad
    Oct 19, 2005
  4. =?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,860
    =?Utf-8?B?SnVhbmpv?=
    Dec 23, 2005
  5. RosH
    Replies:
    0
    Views:
    796
Loading...

Share This Page