p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   How To Populate ListBox from a Secondary Data Sour (http://p2p.wrox.com/showthread.php?t=21686)

luca November 24th, 2004 12:19 PM

How To Populate ListBox from a Secondary Data Sour
Hi all,

I have a listbox control in a datagrid that must be populated with a database table (secondary source) while its value must be set to value of another table (datagrid database table source) which populates my datagrid.

Anybody help me? (C# or VB NET is OK)

mehdi62b November 24th, 2004 01:03 PM

I didnt get what you meant from Secondary DataSource,
for populating every object within datagrid objects you should consider this order,
1-set the grid's DataSource to a datasource,then bind it
2-set that object's DataSource to a datasource,then bind it.

software engineering student.
Looking for a good job for summer 2005.

luca November 24th, 2004 02:08 PM

Sorry for my english.

The problem is that I want to populate a datagrid from a database table. An element of this datagrid is a dropdownlist which gets all the values from another database table and sets the selected value to the original value taken from the first database (the one which has to populate the datagrid)


badgolfer November 25th, 2004 08:48 AM


  I assume that you have created an asp drop down list in you
  datagrid by editing the HTML properties directly ?

  If so lets say you have given this drop down list an ID of

  In you code after you bind the datasource to your datagrid
  you can add something like this:

 dim aItem as DataGridItem
 dim aDrop as DropDownList
 dim i as integer
 For i = 0 To YourDataGrid.Items.Count - 1
            aItem = YourDataGrid.Items.Item(i)
            aDrop = aItem.FindControl("mydrop")
            aDrop.Items.Add("List item 1")
            aDrop.Items.Add("List item 2")
            aDrop.Items.Add("List item 3")

this should add the 3 list items to each drop down list control
in your datagrid.

mehdi62b December 1st, 2004 05:24 PM

you could bind your DropDownList in ItemDataBound event this event fires after datagrid bindings,

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.SelectedItem ||
                e.Item.ItemType == ListItemType.EditItem)
                    DropDownList ddlInspectors = (DropDownList) e.Item.FindControl("mydrop");
                    ddlInspectors.DataTextField = "ASPECTID";
                    ddlInspectors.DataValueField = "ASPECTID";
                    ddlInspectors.DataSource = ds.Tables[1].DefaultView;


software engineering student.
Looking for a good job for summer 2005.

All times are GMT -4. The time now is 02:35 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.