Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 24th, 2004, 11:19 AM
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, 12: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, 01: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, 07: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, 04: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.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 01:58 AM.


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