Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a master table called master_litigants
i m populating this data into a dropdown list
the table as follows:-
Litigant_id Litigant_type Litignat_value
1 PETITIONER P
2 RESPONDENT R
3 THIRD PARTY T

ddlLitigantType.DataTextField = "Litigants_Type";
ddlLitigantType.DataValueField = "Litigants_value";
ddlLitigantType.DataBind();
I have inserted Value that is(P,R,T) into other table

for updation i read the data from other and want to show in the dropdown list
for that i m using code
1)ddlLitigantType.SelectedValue = dr["Litigant_type"].ToString();
and
2)ddlLitigantType.Items.FindByValue(dr["Litigant_type"].ToString()).Selected = true;
both code showing Error:

Error for 1)st code is:-ddlLitigantType has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value(But the ddlLitigant is loaded in the page load only so the value is present)
Error for 2)nd code is:-Object reference not set to an instance of an object.

m i doing it wrong r is there any other way of doing it.
plZ help me
Posted

This code "ddlLitigantType.SelectedValue = dr["Litigant_type"].ToString();" works if u write it after binding dropdownlist items. However it should exist in the dropdownlist items.
 
Share this answer
 
You must have matching Items in both Dropdownlist and the database.and you should bind data before execute below lines
C#
ddlLitigantType.DataTextField = "Litigants_Type";
ddlLitigantType.DataValueField = "Litigants_value";


but it seems you don't have matching values. thats why you are getting 2nd error
 
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