c# - Setting dropdownlist selected index -
I have a dropdown list with the name of the country in alphabetical order. I always show the dropdown to India as the default value I want to put in. I do not want to set the selected index with constant because other countries can be added later in the list, how can I set the index to "India"?
ddlCountryCode.DataSource = ds1.Tables ["AUser"]; DdlCountryCode.DataTextField = "Contra Contro"; DdlCountryCode.SelectedIndex = ddlCountryCode.Items.IndexOf (ddlCountryCode.Items.FindByText ("India (+91)")); DdlCountryCode.DataBind (); does not work ...
dropdown list 1. Selected index = dropdown list 1 Items.indexoff (dropdown list 1.tems.findbay value (str Text)); or
dropdown list 1 Selected index = dropdown list 1 Items.indexoff (dropdown list1 item .Fundbit text (str Text)); Reference
1
Change the order of your code
ddlCountryCode.DataSource = DS 1.Tables ["AUser"]; DdlCountryCode.DataTextField = "Contra Contro"; DdlCountryCode.DataBind (); DdlCountryCode.SelectedIndex = ddlCountryCode.Items.IndexOf (ddlCountryCode.Items.FindByText ("India (+91)"));
Comments
Post a Comment