本文介绍了下拉列表数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好, 我正在使用部门的下拉列表 我的部门包含 1 2 3 部门 当我使用数据源时,它仅显示1 2 3. 我想显示选择一个部门值"作为第一个,如何实现. 我的代码是:
Hi All, I am using drop down list for department my dept contains 1 2 3 departments When i am using data source it is showing only 1 2 3 . I want to display "select a dept value" as first one, how can I achieve that. my code is:
<asp:DropDownList ID="ddlDept" runat="server" DataSourceID="SqlDataSource1" DataTextField="DeptID" DataValueField="DeptID" Font-Underline="False"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EmployeeDetailsConnectionString4 %>" SelectCommand="SELECT DISTINCT [DeptID] FROM [Department]"> </asp:SqlDataSource>请帮帮我. 在此先感谢.
please help me. Thanks in Advance.
推荐答案ConnectionStrings:EmployeeDetailsConnectionString4 %> " SelectCommand =" 从[部门]中选择[DeptID]" > ; < /asp:SqlDataSource > ConnectionStrings:EmployeeDetailsConnectionString4 %>" SelectCommand="SELECT DISTINCT [DeptID] FROM [Department]"> </asp:SqlDataSource>
请帮帮我. 预先感谢.
please help me. Thanks in Advance.
尝试一下... Try this ... ddlDept.Items.Insert(0, new ListItem("--select a dept value--", "-1"));
<asp:DropDownList ID="ddlDept" runat="server" DataSourceID="SqlDataSource1" DataTextField="departments" DataValueField="DeptID" Font-Underline="False"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%
更多推荐
下拉列表数据源
发布评论