Solved

Bind datagrid to a dropdownlist

Posted on 2004-10-07
3
400 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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