Click here to Skip to main content
11,438,069 members (47,845 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 8:41am
Edited 7-Oct-12 8:42am
v2
Comments
Wes Aday at 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 at 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 at 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 :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 8-Oct-12 4:10am
   
yes exactly i want this which you mentioned above sir.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  

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



Advertise | Privacy | Mobile
Web01 | 2.8.150506.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100