如何选择一个DropDownList的所有记录 [英] How to select all records in a DropDownList
问题描述
我有这样的DropDownList:
I have this DropDownList:
<asp:DropDownList ID="DropDownList1"
runat="server"
AutoPostBack="true"
DataSourceID="SqlDataSource1"
DataTextField="Categorie"
DataValueField="Cat_ID"
>
</asp:DropDownList>
和在SqlDataSource 选择[tbl_Cat] *所有
and the SqlDataSource select * all from [tbl_Cat]
它用于通过类别进行过滤数据库。它完美地工作,但只显示了三个类别都在 tbl_Cat
。我也希望有一个选择在DropDownList所有
项。
It's used to filter the database via category. It works perfectly, but it only shows the three categories that are in the tbl_Cat
. I also want a select all
item in the DropDownList.
DropDownList控件和数据网格不与code-背后作出的;是否有可能通过进入选择所有记录选项,code-后面?
The DropDownList and the datagrid are not made with code-behind; is it possible to enter a "select all records" option through code-behind?
推荐答案
您需要编写低于code,帮助您选择类别的所有选项。
You need to write the below code which help you to select all option for category.
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server">
</asp:DropDownList>
在$后面的文件c $ C
In Code behind file
SqlConnection con = new SqlConnection(str);
string com = "select * all from tbl_Cat";
SqlDataAdapter adpt = new SqlDataAdapter(com, con);
DataTable dt = new DataTable();
adpt.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.DataTextField = "Categorie";
DropDownList1.DataValueField = "Cat_ID";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("Select ALL", "0"));
现在,你可以检查是否下拉选择的值是0,如果是0,那么你可以在电网负荷中的所有记录。
Now you can check if drop down selected value is 0, if it is 0 then you can load all the records in the grid.
让我知道,如果任何事情,我错过了。
Let me know if any thing i miss.
这篇关于如何选择一个DropDownList的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!