/// <summary> /// 绑定代表下拉选项 /// </summary> public void BindOwnerDataII(string unitId, string bindid) { BaseCore obj = new BaseCore(); DataTable dt = obj.GetOwnerByBusiness(unitId); this.ddlOwner.DataSource = dt; this.ddlOwner.DataTextField = "fullname"; this.ddlOwner.DataValueField = "systemuserid"; this.ddlOwner.DataBind(); this.ddlOwner.SelectedValue = bindid; this.ddlOwner.Items.Insert(0, new ListItem("全部", "00000000-0000-0000-0000-000000000000")); }
我的问题是 应该是由于 字符的大小写引起的, 因为 this.ddlOwner.SelectedValue = bindid; bindid 为大写的GUID,但是 dt中的元素都是小写的,这里是什么原因我不知道,因为
GetOwnerByBusiness(unitId);从数据库中取到的GUID全部为大写的.
改为使用下面的语句就看出问题来了,如果是大写的GUID会报错,所以把bindid 转换为小写了,这样就正常了.
this.ddlOwner.Items.FindByValue(bindid.ToLower()).Selected = true;