Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
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 7-Oct-12 7:41am
Edited 7-Oct-12 7:42am

Comments
Wes Aday - 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.
" 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 :(

2 solutions

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
 
DropDownList1.SelectedValue = DropDownList1.Items.FindByText(dr["CountryName"].ToString()).Value;
  Permalink  
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.
  Permalink  
Comments
Surendra0x2 - 8-Oct-12 4:10am
yes exactly i want this which you mentioned above sir.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Prasad_Kulkarni 407
1 _Amy 336
2 Sergey Alexandrovich Kryukov 327
3 OriginalGriff 235
4 Christian Graus 223
0 Sergey Alexandrovich Kryukov 6,649
1 Prasad_Kulkarni 3,281
2 _Amy 3,065
3 OriginalGriff 2,989
4 CPallini 2,696


Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid