Click here to Skip to main content
14,867,815 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Code Behind :

C#
private void BindDropDown()
    {
        using (SqlConnection con = new SqlConnection(@"Data Source=maj-056\sqlexpress;Initial Catalog=Sample;Integrated Security=True;Pooling=False"))
        {
            SqlCommand cmd = new SqlCommand("sp_select", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                DropDownList1.DataSource = ds.Tables[0];
                DropDownList1.DataTextField = "";
                DropDownList1.DataValueField = "";
                DropDownList1.DataBind();

                DropDownList2.DataSource = ds.Tables[1];
                DropDownList2.DataTextField = "";
                DropDownList2.DataValueField = "";
                DropDownList2.DataBind();

                DropDownList3.DataSource = ds.Tables[2];
                DropDownList3.DataTextField = "";
                DropDownList3.DataValueField = "";
                DropDownList3.DataBind();
            }
        }
    }



SQL Query :


SQL
create proc sp_select
as
begin
select * from Table1
end
begin
select * from Table2
end
begin
select * from Table3
end
Posted
Updated 10-Aug-11 6:31am
v2
Comments
BoxyBrown 10-Aug-11 10:44am
   
what exactly you want to do? What you want to see in dropdownlist?
rahkan 10-Aug-11 10:46am
   
Was there a question in there somewhere?
Dr.Walt Fair, PE 10-Aug-11 14:03pm
   
I think the answer is Liquid Nitrogen.
Monjurul Habib 10-Aug-11 15:19pm
   
:) why thought like that?

That ain't gonna work. You have to at least specify the DataText fields.

And NEVER use Select * in a query.
   
v2
Read the following article and modify your procedure accordingly:
http://blog.sqlauthority.com/2008/10/15/sql-server-introduction-and-example-of-union-and-union-all/[^]
   
You will have to mention the Datavalue and DataText fields for each of your drop down list.


The datavalue and datatext fileds should be the existing column names in your respective tables to which you are binding you repective drop down.


Hope this will help you!!!!
   
hiii
.
y dont u gve datatext field and and datavaluefield?
   
Comments
nagendrathecoder 11-Aug-11 7:30am
   
Nothing different from above answers.
Ashika s 11-Aug-11 23:19pm
   
i just gve the answer as i know ..............i didnt like to ompare drom above answer.........depend my knowledge not others ........
Manfred Rudolf Bihy 12-Aug-11 10:53am
   
No text speak please! Read the FAQ. Again these surplus characters, stop this immediately.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900