Solved

Bind datagrid to a dropdownlist

Posted on 2004-10-07
3
394 Views
Last Modified: 2012-06-27
Ok, here's my scenario...

Intranet with Windows Authentication
ASP.NET Web page that has the following: label to get user NTID (lblID), dropdownlist (DDL), datagrid (DG).
SQL tables - tblUsers table and a tblProjects table
DDL is populated on Page_Load by fields from tblUsers (NTID and Name)
Datagrid is populated by * from tblProjects

Here's what I'm looking to do...
On page load, get the user's NTID, sort the DDL so that the user's NTID is first in the list of values displayed.
Use the value of the DDL as a parameter to tblProjects to retrieve records associated with that NTID. Bind DG to that data.
On postbacks have the DG update based on change to DDL selected item.
I'm looking to avoid the use of any buttons.
I am also looking to be able to add a 'ALL NTIDs' option (ALL Records) to the DDL so that the user can retrieve all projects.

Any ideas?


0
Comment
Question by:SWRO
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 250 total points
Comment Utility
Look like you've got a lot of things here, though I am not sure what you mean by "NTID".  If you mean the login name, that can be accessed by User.Identity.Name, which will return the name as "domain\username".  You can parse out the user name.  If this is what you mean, and you have a ddl with user names in it, then what you want to do is this:

In Page_Load, if the page is not a postback, get the data for your ddl from tblUsers and bind the ddl to it.  After you call DataBind() on the dll, do this:

*********
if not page.ispostback then
     ' parse out the NTID from User.Identity.Name
     string userName = ...

     ' find the item by value.
     Dim li as ListItem = ddl.Items.FindByValue(userName)

     ' if the item was found, select it.
     if not li is nothing then li.Selected = true;
end if

 ' fill the projects table based on the selected item.
...

if not page.ispostback then theGrid.DataBind()
**********

Make sure that AutoPostBack on the ddl is True.  Then in the SelectedIndexChanged event of the ddl, requery the tblProjects table based on the selected item of the ddl and call DataBind on the grid.

John
0
 

Author Comment

by:SWRO
Comment Utility
Thanks, I will give it a shot and let you know.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now