about dropdownlist
-
Rajeshwar Code- Developer wrote:
i tried that .. seletedvalue showing null value..
Why does you DropDown list does not have any data ? What are the value of those ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
here the thing is i was many countries binding to ddl frm countries table .. so there is one more table called userdetails. for one user having one country right .. i want show automatically his country inj ddl.
try and try untill reach success..
-
here the thing is i was many countries binding to ddl frm countries table .. so there is one more table called userdetails. for one user having one country right .. i want show automatically his country inj ddl.
try and try untill reach success..
This is my Dropdownlist. [ I assume you are binding it from Database.
us
india
koria
canada[ I have removed / for formatting. ] In page load I am using this,
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.SelectedValue = "india";
}Here rather than india, you should use the value of user country.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
This is my Dropdownlist. [ I assume you are binding it from Database.
us
india
koria
canada[ I have removed / for formatting. ] In page load I am using this,
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.SelectedValue = "india";
}Here rather than india, you should use the value of user country.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
thanks abhijith !!! See my code one.. ddlCountry.SelectedValue = ds.Tables[0].Rows[0]["sCountry"].ToString(); am doing like this ? in Selectedvalue showing null value.
try and try untill reach success..
-
hi!!!! i need to know .. i have one dropdownlist called as ddlcountry. in this ddlcountry i m binding with table name called countries . i have one more table called userdetails .. already one user registered and selected his country frm ddl called USA . so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.
try and try untill reach success..
Rajeshwar First bind the ddlCountry with your country table data and than use below mentioned code to select user's country.
ddlCountry.ClearSelection()
ddlCountry.Items.FindByText("user's country").Selected = TrueBe an Eagle, Sky is Yours.
-
Rajeshwar First bind the ddlCountry with your country table data and than use below mentioned code to select user's country.
ddlCountry.ClearSelection()
ddlCountry.Items.FindByText("user's country").Selected = TrueBe an Eagle, Sky is Yours.
still there is no result..
try and try untill reach success..
-
hi!!!! i need to know .. i have one dropdownlist called as ddlcountry. in this ddlcountry i m binding with table name called countries . i have one more table called userdetails .. already one user registered and selected his country frm ddl called USA . so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.
try and try untill reach success..
When page loads, first Bind the Data with the
dllCountry
. Choose appropriateDataTextField
andDataValueField
. Now after you finish your load usingDataBind
, usethis.dllCountry.SelectedValue
with the DataValueField you want. Also please check if you have wroteIf(IsPostBack)return;
in the Form_Load, so that when the page is posted back the selection remains. :thumbsup:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
When page loads, first Bind the Data with the
dllCountry
. Choose appropriateDataTextField
andDataValueField
. Now after you finish your load usingDataBind
, usethis.dllCountry.SelectedValue
with the DataValueField you want. Also please check if you have wroteIf(IsPostBack)return;
in the Form_Load, so that when the page is posted back the selection remains. :thumbsup:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
Abhishek Sur wrote:
Choose appropriate DataTextField and DataValueField.
I guess he is missing bind with
DataValueField
:)Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
Abhishek Sur wrote:
Choose appropriate DataTextField and DataValueField.
I guess he is missing bind with
DataValueField
:)Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
yes... right. If
DataValueField
is not specified, the value will be same asDataTextField
. I personally always set ID as value so that I could setSelectedValue
with some numeric field orGUID
, asTextField
may repeat. :rose:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Abhishek Sur wrote:
Choose appropriate DataTextField and DataValueField.
I guess he is missing bind with
DataValueField
:)Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
thnks for all who reply me .. i tried like this also bu there is no output.. and this is my code if (!IsPostBack) { DataSet ds1 = new DataSet(); ds1 = ad.dsGetvalues("Select * from Countries", true); ddlCountry.DataSource = ds1; ddlCountry.DataTextField = "sCountryName"; ddlCountry.DataValueField = "sno"; ddlCountry.Items.Insert(0, "--Select--"); ddlCountry.DataBind(); DataSet dss = new DataSet(); dss = ad.dsGetvalues("select * from UserDetails where PkiUsername ='"+Session["Username"].ToString()+"' ", true); ddlCountry.SelectedValue = dss.Tables[0].Rows[0]["sCountry"].ToString(); }
try and try untill reach success..
-
thnks for all who reply me .. i tried like this also bu there is no output.. and this is my code if (!IsPostBack) { DataSet ds1 = new DataSet(); ds1 = ad.dsGetvalues("Select * from Countries", true); ddlCountry.DataSource = ds1; ddlCountry.DataTextField = "sCountryName"; ddlCountry.DataValueField = "sno"; ddlCountry.Items.Insert(0, "--Select--"); ddlCountry.DataBind(); DataSet dss = new DataSet(); dss = ad.dsGetvalues("select * from UserDetails where PkiUsername ='"+Session["Username"].ToString()+"' ", true); ddlCountry.SelectedValue = dss.Tables[0].Rows[0]["sCountry"].ToString(); }
try and try untill reach success..
Rajeshwar Code- Developer wrote:
ddlCountry.DataValueField = "sno";
Try this
ddlCountry.DataTextField = "sCountryName";
ddlCountry.DataValueField = "sCountryName";Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article