?
Solved

Bind datagrid to a dropdownlist

Posted on 2004-10-07
3
Medium Priority
?
405 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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 …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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

762 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