473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

DropDownList Displaying Data from SQL DB

Hi,

I'm trying to display my coded values from my SQL database in a DropDownList.

Basic functionality is I have a createUser page which has a couple drop down choices. I want the user to be able to edit in the editUser page. When the user selects edit, I have all the information pulling up including the value of the drop down, just not sure how code it to display. I'm working with Visual Studio in C#. Any help would be appreciated.

Thanks,
RatPack
Jan 31 '08 #1
4 1434
nateraaaa
663 Expert 512MB
I assume you are using a stored procedure or an sql query to return the data saved for the user. If so you just need to add the record set returned from the database to a dataset. Then create a datatable to hold the table information from your dataset. You will then loop through the rows in your datatable (there should only be one) and set the SelectedValue property of your dropdownlist equal to the value stored in the datatable column. Here is a quick example

Use ADO.NET to add the results of your query to a dataset
.....
sqldataadapter.Fill(ds);

I don't know how you are identifying the user but I usually use a querystring to do that.
Expand|Select|Wrap|Line Numbers
  1. if(Request.QueryString["userId"] != null)
  2. {
  3. DataTable dataTable = ds.Tables[0];
  4. for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
  5. {
  6. DataRow row = dataTable.Rows[i];
  7. if(row["column1"] != System.DBNull.Value)
  8. {
  9. DropDownList1.SelectedValue = row["column1"].ToString();
  10. }
  11. else
  12. {
  13. DropDownList1.SelectedIndex = -1;
  14. }
  15. }
  16. }
Nathan
Jan 31 '08 #2
kunal pawar
297 100+
Do u mean at time of create user Dropdown should be empty or disabled.
Feb 1 '08 #3
debasisdas
8,127 Expert 4TB
You need to fill the dropdown dynamically as per user selection.
Feb 1 '08 #4
nateraaaa
663 Expert 512MB
Do u mean at time of create user Dropdown should be empty or disabled.
The original question asks how to prepopulate values on an Edit page. The dropdownlist should be already populated (page_load event) and then the example code that I posted should follow the code that populates the dropdownlist (also page_load event).

Nathan
Feb 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sunstarwu | last post by:
Hi, I am having difficultly being able to view certain Columns and rows via a DropDownList. Everytime I load my webpage.aspx it just shows empty drop down menus. I have no problem showing all...
2
by: Rui Macdonald | last post by:
What is wrong with this code to populate a DropDownList? Can somebody Help me? Tnx RMac ===================================================================================== WebForm.aspx.vb
6
by: Pat | last post by:
When selecting a DropDownlList to display some Data based on the ddl.SelectedItem.Value since a dropdownlist index starts from 0.. After selecting for example value1 and 2 which its ok but when...
2
by: Rodrigo Ferreira | last post by:
Hello, How can i fill a dropdownlist with data returned by the database? My code is: string strsql = "SELECT designacao FROM categorias"; multiqual.bd db1 = new multiqual.bd();...
2
by: Dabbler | last post by:
I have a number of rows in a GridView Column which don't have values for the DropDownList, is there a way to hide the control if it has no data? Here's my code: <ItemTemplate> <asp:DropDownList...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
0
by: Michael | last post by:
Hi Everyone, I had posted a message about the dropdownlist not displaying newly added items. Just alittle background. I'm working with a masterpage and a usercontrol(Search control) (VS2005) that...
1
by: savvy | last post by:
I am developing a Garments shopping cart. On the single product page where the customer selects size and colour of a garment and if its ok for him, then adds to his basket, so every time he checks...
2
by: zaki.agha | last post by:
Hi I have a aspx application written in c#. I have created a datagrid control on the page. One of the columns in the control is a dropdownlist. I would like to set the data source of the...
1
by: rajiv Joshi | last post by:
Hi all I m displaying locations from database in the dropdownlist box using C# .Its displaying all locations properly but when i select loacation from dropdown it is always displaying first item...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.