Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Location
    South Africa
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP.NET: Data Bound Combo Box In A Data Grid

    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?
    Bypass your proxy and get anonymous internet surfing FREE!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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();
    da.Fill(ds);
    return ds.Tables[0].DefaultView;
    }

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

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Location
    South Africa
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanx BrainJar! Thats exactly what I needed...
    Bypass your proxy and get anonymous internet surfing FREE!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •