Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want To Bind My dropdownlist with the selected value coming from database on the behalf of Session.

suppose there is a Column name Country in the Database and when user Click on Edit Buton then i want Selected Country of User Which he inserted During Registration. and i also want to show All countries too if he wants to change to his Country.
Plz help me Guys Its Very Urgent. :(
Posted
Updated 7-Oct-12 7:42am
v2
Comments
[no name] 7-Oct-12 13:51pm    
And it was so urgent you forgot to ask a question in your haste? How is any of this a problem? Do you not know how to connect to your database (whatever it is)? Do you know know how to write a query? Do you not know how to execute a query?
Surendra0x2 7-Oct-12 13:56pm    
string SqlConnect = System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
SqlConnection Sqlconn = new SqlConnection(SqlConnect);
SqlCommand sqlcomm = new SqlCommand("select * from Category", Sqlconn);
Sqlconn.Open();
SqlDataReader dr = sqlcomm.ExecuteReader();
if (dr.HasRows)
{

DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "CatName";
DropDownList1.DataValueField = "Catid";
DropDownList1.DataBind();

ListItem c = new ListItem("Select Category", "0");
DropDownList1.Items.Insert(0, c);
ListItem d = new ListItem("Select Warranty", "0");
DropDownList2.Items.Insert(0, d);



dr.Close();
Sqlconn.Close();
}

this code can tell u what i know and if u want to help then Welcome.
bbirajdar 7-Oct-12 14:32pm    
" if u want to help then Welcome otherwise Don't Comment"

You are too arrogant.....I wont help you either.......
Surendra0x2 7-Oct-12 14:57pm    
Buddy Sorry But i'm not arrogant look above comment that guy said that "And it was so urgent you forgot to ask a question in your haste? How is any of this a problem? Do you not know how to connect to your database (whatever it is)? Do you know know how to write a query? Do you not know how to execute a query?" this thing made me sad thats y i said to him not to comment its not for you Buddy :(

Clear first..I m in Little bit confusion so clear first what u want exactly-->
You want display the current country name after load the page, as user choose at the time of registration. Which is save in database and also show append list of County name below it.
 
Share this answer
 
Comments
Surendra0x2 8-Oct-12 4:10am    
yes exactly i want this which you mentioned above sir.
I Solved My Problem

On Page Load Event i Populated Dropdown with Countrylist
and
then i called a method on page load
which will select the value of counrty on the behalf of Session value

HTML
DropDownList1.SelectedValue = DropDownList1.Items.FindByText(dr["CountryName"].ToString()).Value;
 
Share this answer
 

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