下拉列表内容覆盖 [英] Dropdownlist Content Overwrite

查看:83
本文介绍了下拉列表内容覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strSQL = "SELECT * FROM User_Reg WHERE User_ID='" + UserId + "'";
        DataTable dataTablerepeaterUserList = null;
        dataTablerepeaterUserList =objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];


foreach (DataRow dr in dataTablerepeaterUserList.Rows)
        {          

            ddlTitle.SelectedItem.Text = dr["Title"].ToString();
        }


<asp:DropDownList ID="ddlTitle" runat="server" CssClass="csstextbox" >
                       <asp:ListItem>Mr.</asp:ListItem>
                       <asp:ListItem>Mrs.</asp:ListItem>
                       <asp:ListItem>Miss.</asp:ListItem>
                        <asp:ListItem>Dr.</asp:ListItem>
                   </asp:DropDownList>





if suppose  dr["Title"]=Dr.
then it is overwrite Mr. with Dr. and got result like.  | Dr.  |
                                           | Mrs. |
                                           | Miss.|
                                           | Dr.  |


我将View_User.aspx中的User_ID传递给Create_User.aspx,以便使用querystring..Id正确编辑用户目的..在Create_User.aspx中显示所有正确的字段..所有控件都正确获取了正确的数据,但是当我填充当前标题时用户,然后用dropdownlist的第一项覆盖它.(我对Dropdownlist唯一的问题是它被覆盖了)


i am passing User_ID from View_User.aspx to Create_User.aspx For edit user purpose using querystring..Id getting proper.. showing all correct fields in Create_User.aspx ....All control get correct data properly but when i populate title of current user then it overwrite with first item of dropdownlist.(I have only problem with Dropdownlist it is overwritten)

推荐答案

string s = dr["Title"].ToString(); 
ddlTitle.SelectedText = s;



您可以一行完成它,我只是这样做,以使其更易于阅读.如果字符串 s 不在列表中,则会抛出错误.



You can do it in one line, I just did it like that to make it easier to read. This will throw an error if the string s is not in the list.


使用选定的值
Use selected value
ddlTitle.SelectedValue = dr["Title"].ToString();

change this line also
<asp:dropdownlist id="ddlTitle" runat="server" cssclass="csstextbox" xmlns:asp="#unknown">
                  <asp:listitem text="Mr." value="Mr."></asp:listitem>
                  <asp:listitem text="Mrs." value="Mrs."></asp:listitem>
                  <asp:listitem text="Miss." value="Miss.">Miss.</asp:listitem>
                  <asp:listitem text="Dr." value="Dr.">Dr.</asp:listitem>
</asp:dropdownlist>


尝试一下,它应该可以工作....


try this, it should work....


ddlTitle.SelectedItem = dr["Title"].ToString();


这篇关于下拉列表内容覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆