473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populate dropdown items via stored procedure

14 New Member
Hi All,

I am new to this field, and is using VS.2005, language is C#.

1) created a database "Test" in sql 2005, had a table "NameList", a stored proc "GetAllName "
2) created a new website, on .aspx page has a dropdown control "ddlName"

Wish could have help at following:

Now I want to all the names from NameList will be populated at 'ddlName" when page loaded.

There is no problem for me to complete this task using data adapter, but I want to use stored procedure.

Thank you in advance. Your time is great appreciated.

ellen89
Mar 11 '08 #1
8 1427
nateraaaa
663 Recognized Expert Contributor
Please see the following article in our Howtos section.

http://www.thescripts.com/forum/thread635615.html

Nathan
Mar 11 '08 #2
ellen89
14 New Member
nateraaaa,

Thank you very much for your time.

Now I had another problem, my code is:

protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
string cnString = ConfigurationMa nager.Connectio nStrings["TestConnection String"].ConnectionStri ng;
SqlConnection cnn = new SqlConnection(c nString);
SqlCommand cmd = new SqlCommand("Get AllName", cnn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.CommandText = "GetAllName ";
cnn.Open();

SqlDataAdapter da = new SqlDataAdapter( );
da.SelectComman d = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "NameList") ;
DropDownList1.D ataSource = ds;
DropDownList1.D ataMember = "NameList";
DropDownList1.D ataBind();

cnn.Close();
}
}

But the at Dropdown list will have "System.Data.Dat aRowView" instead of real data.
Mar 12 '08 #3
saran23
28 New Member
nateraaaa,

Thank you very much for your time.

Now I had another problem, my code is:

protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
string cnString = ConfigurationMa nager.Connectio nStrings["TestConnection String"].ConnectionStri ng;
SqlConnection cnn = new SqlConnection(c nString);
SqlCommand cmd = new SqlCommand("Get AllName", cnn);
cmd.CommandType = CommandType.Sto redProcedure;
cmd.CommandText = "GetAllName ";
cnn.Open();

SqlDataAdapter da = new SqlDataAdapter( );
da.SelectComman d = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "NameList") ;
DropDownList1.D ataSource = ds;
DropDownList1.D ataMember = "NameList";
DropDownList1.D ataBind();

cnn.Close();
}
}

But the at Dropdown list will have "System.Data.Dat aRowView" instead of real data.
Hi, The problem is in this line,
Expand|Select|Wrap|Line Numbers
  1. DropDownList1.DataSource = ds;
ur binding a dataset to a dropdownlist, a dataset may contain more than one table also, so there comes the problem, even if u hv used Datamember,the table name to which the "NameList" column belongs is not specified,So u hv to do this,

Expand|Select|Wrap|Line Numbers
  1. DropDownList1.DataSource = ds.Tables[0]
The '[0]' denotes the index of the datatable in the dataset.

Im sure this works...

Thanks
Saran
Mar 12 '08 #4
ellen89
14 New Member
Sarah,

Thank you very much. I had tried, unfortunately, I have no lucky.

I am not sure the .DataMember property, NameList is my table name, with 2 columns (firstName, lastName).

Gusee I should not have the column name in my code because I am using stored procedure to get the result. This stored procedure is very simple and tested in sql server 2005.

Thanks again,

ellen89
Mar 12 '08 #5
kunal pawar
297 Contributor
Hi, ur code correct but to display text in drop down control u have to set column name, same for value

DropDownList1.D ataSource = ds;
DropDownList1.D ataValueField = "Field name for selected item value"
DropDownList1.D ataTextField = "Field name for selected item Text"
DropDownList1.D ataBind();
Mar 12 '08 #6
ellen89
14 New Member
Thank you!

Now the problem is I want to show the full name on the dropdown list, but the Name is stored in databas as FirstName & LastName (2 columns).

What should I put for DropDownList1.D ataTextField ?

I had tried DropDownList1.D ataTextField = "FirstName+ ' '+LastName", it gave run time error.

ellen89
Mar 16 '08 #7
ellen89
14 New Member
I had solved this problem by using a VIEW table at SQL server to have FirstName and LastName at same column.

Thank you for all help.

ellen89
Mar 16 '08 #8
kunal pawar
297 Contributor
You not need to create view for this single reason, just add column in ur sql query
as FirstName + ' '+LastName as Name.

and

DropDownList1.D ataTextField = "Name"
Mar 17 '08 #9

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

Similar topics

20
12370
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer input of product names to put on custom labels we make. Some of the labels will have our product names on them, but the customer can add other...
1
1976
by: Mark Goldin | last post by:
How can I populate a dropdownlist with data from a database using Microsoft.ApplicationBlocks.Data ? Thanks
3
2685
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other...
3
1160
by: JIM.H. | last post by:
Hello, I have two Tables: Table1: GroupID1, GroupName1 and Table2:GroupID2, GroupName2. I have only one dropdown list (DropDownList1) in my application and through a stored procedure I want to populate my DropDownList1 from GroupName1 and GroupName2. How should I write my query? Thanks, Jim.
3
2413
by: Chris Kettenbach | last post by:
Hello all, Quick question. I have a listbox that is populated by items from a database. When the user select something from the list, I want to populate another listbox based on the selection in the first. Example lstCompany contains a list of company names with the primary key field hidden. After user selects a company, I want to pass that...
6
3923
by: blouie | last post by:
Is there a way that a bound ddl control can: 1. display the bound data, even if it does not match a selection in the DDL? 2. allow the user to enter something other than the look up values? I have a bound dropdown list that retrieves it's selections from a look-up table. The DDL is bound to a database table and unless the value in the...
1
1655
by: Mike P | last post by:
I am trying to populate a dropdown from a stored procedure, but I am getting the error 'Object doesn't support this property or method: 'Next' : <!--#include file="include_connection.asp"--> <!--#include file="adovbs.inc"--> <% set objConn = server.createobject("adodb.connection")
0
1760
by: Javilen | last post by:
Hello, Maybe one of you can offer a possible solution to the problem I have below. The request to me is to build a dynamically populating dropdown list from a text box.(something similar to Google Suggest.) The idea is that the client wants to come in and search for something but may only know part of the name. So they type it in. Eg....
0
2746
TonFrere
by: TonFrere | last post by:
Hello, I'm building a windows form application in Visual C# using VS 2005. On my form I need to populate a combobox with Invoices# linked to the current reccord's Order# value. This means that: - The combobox should repopulate if the user changes the value of Order#. - The combobox should repopulate if the user moves through records (using the...
1
1140
by: ellen89 | last post by:
Hi All, I am new to this field, and is using VS.2005, language is C#. 1) created a database "Test" in sql 2005, had a table "NameList", a stored proc "GetAllName" 2) created a new website, on .aspx page has a dropdown control "ddlName" Wish could have help at following: Now I want to all the names from NameList will be populated at...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.