473,322 Members | 1,431 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,322 software developers and data experts.

How to Populate the Dropdownlist control in C#...

14
Hi..
I'm using Asp.Net with C#....

I'm having One Dropdownlist control(Users_Details_DDL) in Default.aspx Page...

i'm having one Stored Procedure (Get_User_Email) which will display the Data from Database into Dropdownlist control..
Now I'm populating this Dropdownlist control with Stored Procedure in Default.aspx Page... It is working Fine..

This is the way How i'm Populating the Dropdownlist Control in Default.aspx Page..

---------------------------------------------------------------------------------------------------------------------
Page_Load event(----------------)
{
Connection.Open();

if (!IsPostBack)
{
try
{

SqlCommand cmd = new SqlCommand("Get_User_Email", Connection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader sqlReader = cmd.ExecuteReader();

if (sqlReader.HasRows)
{
Users_Details_DDL.DataSource = sqlReader;
Users_Details_DDL.DataTextField = "User_Email";
Users_Details_DDL.DataValueField = "User_ID";
Users_Details_DDL.DataBind();
sqlReader.Close();
}
}
catch (SqlException ex)
{
ErrorLabel.Text = ex.Message;
ErrorLabel.Visible = true;
}
finally
{
// Close the database connection
//dbHelper.closeDatabaseConnection(dbConn);
}
}
---------------------------------------------------------------------------------------------------------------------

Now i want to do the Same Operation by using Class file (Class1.cs)..

ie I want to Populate the Dropdownlist control with Stored Procedure from Class File(Class1.cs) instead of from Default.aspx Page in C#..

(Here i'm not using any Datasets)

How to do this... Please give me the Code....


Thank You...
Feb 1 '08 #1
2 4397
dip_developer
648 Expert 512MB
Hi..
I'm using Asp.Net with C#....

I'm having One Dropdownlist control(Users_Details_DDL) in Default.aspx Page...

i'm having one Stored Procedure (Get_User_Email) which will display the Data from Database into Dropdownlist control..
Now I'm populating this Dropdownlist control with Stored Procedure in Default.aspx Page... It is working Fine..

This is the way How i'm Populating the Dropdownlist Control in Default.aspx Page..

---------------------------------------------------------------------------------------------------------------------
Page_Load event(----------------)
{
Connection.Open();

if (!IsPostBack)
{
try
{

SqlCommand cmd = new SqlCommand("Get_User_Email", Connection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader sqlReader = cmd.ExecuteReader();

if (sqlReader.HasRows)
{
Users_Details_DDL.DataSource = sqlReader;
Users_Details_DDL.DataTextField = "User_Email";
Users_Details_DDL.DataValueField = "User_ID";
Users_Details_DDL.DataBind();
sqlReader.Close();
}
}
catch (SqlException ex)
{
ErrorLabel.Text = ex.Message;
ErrorLabel.Visible = true;
}
finally
{
// Close the database connection
//dbHelper.closeDatabaseConnection(dbConn);
}
}
---------------------------------------------------------------------------------------------------------------------

Now i want to do the Same Operation by using Class file (Class1.cs)..

ie I want to Populate the Dropdownlist control with Stored Procedure from Class File(Class1.cs) instead of from Default.aspx Page in C#..

(Here i'm not using any Datasets)

How to do this... Please give me the Code....


Thank You...
build a class....create a public function........put your data transaction code in the function ......return the datareader.....
in the cose behind....create a class object......and call your function......what problem....????
Feb 1 '08 #2
Aswanth
14
build a class....create a public function........put your data transaction code in the function ......return the datareader.....
in the cose behind....create a class object......and call your function......what problem....????
Could you Please give me the code... of doing this...
Feb 1 '08 #3

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

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
2
by: Jim via DotNetMonster.com | last post by:
Hi, I'm passing a variable to another page through a querystring. I then want to use that variable to retrieve records from a database to poulate a dropdownlist. I can read the variable from the...
1
by: mr2_93 | last post by:
Hi All, I am new to ASP.NET and I am looking for help with the dropdownlist data control. I wonder if someone could show me how to past the SelectedValue of a data-bind dropdownlist to...
2
by: bobbyc13 | last post by:
I am new to vb.net and am getting frustrated and cannot find a post on the subject. I have a usercontrol (.ascx) with a dropdownlist. on the selectedindexchanged event of the codebeside of the...
3
by: sweetpotatop | last post by:
Hi, I am try to populate a number of dropdownlist with the same item, for i = 1 to 5 dd = me.controls("dd" + Cstr(i)) itm = new listiem itm.text ="abc" itm.value ="aaa"
6
by: peerraghu | last post by:
hi i am developing website which is a online shoping i want to populate two dropdownlist, in which the first dropdownlist should place the list of a paticular product and the next dropdownlist...
1
by: sudip2008 | last post by:
When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm This breaks this line from working properly window.opener.document.forms...... How can...
5
by: =?Utf-8?B?U2F0aXNo?= | last post by:
C#, ASP.NET Q: Have a formview, with a dropdownlist which is bound to a column. This dropdownlist has a datasource of DataSet type. Now my objective is, on Selection Changed of this DropdownList,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.