使用HTML5 FindByValue的DropDownList [英] html5 dropdownlist using FindByValue
问题描述
我的DropDownList HTML5
my dropdownlist HTML5
<select runat="server" id="ddlStateLegalRes" name="ddlStateLegalRes"></select>
在我的网页加载我我的DropDownList绑定到一个列表收集与国家的名单
On my page load I am binding my dropdownlist to a list collection with a list of states
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<StateList> states = ops.getStates();
ddlStateLegalRes.DataTextField = "StateRegionName";
ddlStateLegalRes.DataValueField = "StateRegionCode";
ddlStateLegalRes.DataSource = states;
ddlStateLegalRes.DataBind();
GetAllInfo();
EDITED *的 * 的
有事情很奇怪,我似乎无法找出它,当我调试。由于一些奇怪的原因,这是因为它的工作是应该,但随后开始引发此错误对象引用不设置到对象的实例
EDITED** There is something weird going on and I cant seem to pinpoint it when I debug. For some strange reason this was working as it is supposed to but then started throwing this Error "Object Reference not set to an instance of an object"
我知道名单收集得到正确的价值观,我也知道STATEOFLEGALRESIDENCE是由我的存储过程返回值为FL和拼写是否正确。
I know the list collection is getting the correct values and I also know that "STATEOFLEGALRESIDENCE" is being returned by my stored procedure with the value "FL" and the spelling is correct.
"""Inside my GetAllInfo() method
while (sdr.Read())
{
ddlStateLegalRes.Items.FindByValue(sdr["STATEOFLEGALRESIDENCE"].ToString()).Selected = true;
}
我怀疑的是,它试图把我的DropDownList与前值实际上是做了code结合我的DropDownList与价值观。所以我试图给GetAllInfo()方法移动到Page_LoadComplete事件,仍然是同样的错误所以现在我在一个失去了,请帮助
What i suspect is that it is trying to set my dropdownlist with a value before the code is actually done binding my dropdownlist with values. So i tried to move the GetAllInfo() method into the Page_LoadComplete event and still the same error so now I am at a lost please help
感谢
推荐答案
这听起来就像是从阅读器返回的值不完全匹配,或者是从列表项缺失。
It sounds like the value that is returned from the reader does not match exactly or it is missing from the list items.
我把在点与放一个破发点;检查这些值匹配:
I would put a break point at the point & check that these values match:
试试这个,但与该项目的值替换0。
Try this but replace 0 with the value of the item.
ddlStateLegalRes.Items[0] == sdr["STATEOFLEGALRESIDENCE"].ToString());
这听起来像一个案件或空格triong问题。
It sounds like a case or white space triong issue.
这篇关于使用HTML5 FindByValue的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!