Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 24th, 2004, 12:19 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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)
Thanks!!
  #2 (permalink)  
Old November 24th, 2004, 01:03 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
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.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
  #3 (permalink)  
Old November 24th, 2004, 02:08 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)

Thanks!!
  #4 (permalink)  
Old November 25th, 2004, 08:48 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Whitstable, , United Kingdom.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

  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
  'mydrop'.

  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")
 Next

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



  #5 (permalink)  
Old December 1st, 2004, 05:24 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

you could bind your DropDownList in ItemDataBound event this event fires after datagrid bindings,
Code:
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;
                    ddlInspectors.DataBind();
                }
            }

}
_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default values when setting up an object data sour mikener ASP.NET 2.0 Professional 0 November 3rd, 2008 09:12 AM
Populate ListBox seananderson Access VBA 13 April 18th, 2007 11:46 AM
Secondary Data Source for Word Template Loralee Access 2 May 9th, 2006 07:48 PM
How to: Populate Filename to listbox? mdtcao Beginning VB 6 1 May 11th, 2005 10:25 PM
Listbox doesn't populate all the records edcaru Access 1 April 25th, 2004 10:32 AM





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