问题描述
我有一个名为master_litigants的主表
我将这些数据填充到一个下拉列表中
表格如下:-
Litigant_id Litigant_type Litignat_value
1 PETITIONER P
2响应R
3第三方T
ddlLitigantType.DataTextField ="Litigants_Type";
ddlLitigantType.DataValueField ="Litigants_value";
ddlLitigantType.DataBind();
我已将is(P,R,T)的值插入其他表中
为了更新,我从其他位置读取了数据,并希望显示在下拉列表中
为此,我正在使用代码
1)ddlLitigantType.SelectedValue = dr ["Litigant_type"].ToString();
和
2)ddlLitigantType.Items.FindByValue(dr ["Litigant_type"].ToString()).Selected = true;
两个代码都显示错误:
1)第一个代码的错误是:-ddlLitigantType的SelectedValue无效,因为它不存在于项目列表中.参数名称:值(但是ddlLitigant仅在页面加载中加载,因此存在该值)
2)第一个代码的错误是:-对象引用未设置为对象的实例.
我做错了吗r还有其他方法吗?
请帮助我
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 RESPONDENTR
3 THIRD PARTYT
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
推荐答案
ddlLitigantType.DataTextField = "Litigants_Type";
ddlLitigantType.DataValueField = "Litigants_value";
但似乎您没有匹配的值.那就是为什么您遇到第二个错误
but it seems you don''t have matching values. thats why you are getting 2nd error
这篇关于在DropDownList中选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!