Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
int brand = int.Parse(dr[8].ToString());
               string b_id = (brand - 1).ToString();
               ddbrandname.Items.FindByValue(b_id).Selected = true;



this is my code,i am getting 'id' from table through sqldatareader ,in my drop down list the "select" as 0.
Text |value
select - 0
chennai - 1
trichy - 2
Madurai - 3

if , 3 as my reader value and i m binding by the above code,it shows error,
but if i decrease 1 value from 3 like (3-1) =2 .

if it is 2 ,its working pakka,if its 3 its shows error,
Posted
Comments
Karthik_Mahalingam 29-Nov-13 3:35am    
if it is 2, what value (text) is displayed in the drop down list ???

1 solution

In the brand variable if you are getting value as 1, 2 & 3 then you can directly set the selected value in dropdown as

C#
ddbrandname.SelectedValue=brand.ToString();


This should work for sure!!!!
 
Share this answer
 
v2

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