Solved

Bind datagrid to a dropdownlist

Posted on 2004-10-07
3
402 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
ID: 12256536
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
ID: 12278839
Thanks, I will give it a shot and let you know.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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