Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Bind datagrid to a dropdownlist

Posted on 2004-10-07
3
Medium Priority
?
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 750 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

604 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