如何将ALL添加到从表中填充的下钻列表中 [英] How to add ALL to a drill down list popuated from a table
问题描述
从表格中填充向下钻取列表(即.ddl),使用户能够一次选择一条记录,以便在'加载事件'上进行报告 < br $> b $ b
我想在添加'ALL'中介绍,以便
选择此选项时,报告将针对所选记录的所有记录。
我如何实现这一目标。 />
样品表
代码名称
-------- --------
b001 apple
b002 orange
boo3 pear
需要包含'ALL'作为填写钻取列表的代码记录的一部分。
请协助。
谢谢
Populating a drill down list (ie .ddl) from a table which enables the user to select one record at a time for reporting at 'on load event'
I want to introduce in addition 'ALL' so that,
when this option is selected the report will be for all records as against the selected record.
How do I achieve that.
sample table
code name
----------------
b001 apple
b002 orange
boo3 pear
Need to include 'ALL' as part of the code records populating the drill drown list.
Please assist.
Thanks
推荐答案
你可以在之后为数据添加一行你在程序中读到它,或者在获得数据时使用SQL添加一行...
然后你需要一些编程来确定是否显示一行或所有的详细信息
类似
You can either add a row to the data after you read it into your program, or add a row using SQL when you get the data...
Then you need some programming to determine whether to show details for a row or for all
something like
Select null as code, 'All' as name
union
Select code, name from FruitTable
order by code
然后,在你处理被选中行的事件中
Then, in your event that handles the row being selected
if (selectedObject.Code.hasValue)
DoReportForOneRecord(selectedObject.Code);
else
DoTheReportForAllRecords();
请尝试以下代码
方法1:
Try the below code
Approach 1:
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!this.IsPostBack)
{
sqlCon = new SqlConnection("Data Source=yourservername; Initial Catalog=yourdatabasename;User ID=yourusername;Password=yourpassword");
sqlCon.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter("Select * from cCity", sqlCon);
DataTable dt1 = new DataTable();
sqlDa.Fill(dt1);
DropDownList1.DataTextField = "cityname";
DropDownList1.DataValueField = "cityid";
DropDownList1.DataSource = dt1;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("All", "0"));
}
}
catch (Exception ex)
{ Response.Write(ex.Message.ToString()); }
}
方法2:
Approach 2:
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!this.IsPostBack)
{
sqlCon = new SqlConnection("Data Source=yourservername; Initial Catalog=yourdatabasename;User ID=yourusername;Password=yourpassword");
sqlCon.Open();
SqlDataAdapter sqlDa = new SqlDataAdapter("Select * from cCity", sqlCon);
DataTable dt1 = new DataTable();
sqlDa.Fill(dt1);
DataRow dr = dt1.NewRow();
dr["cityid"] = "0";
dr["cityname"] = "All";
dt1.Rows.InsertAt(dr, 0);
DropDownList1.DataTextField = "cityname";
DropDownList1.DataValueField = "cityid";
DropDownList1.DataSource = dt1;
DropDownList1.DataBind();
}
}
catch (Exception ex)
{ Response.Write(ex.Message.ToString()); }
}
希望它有所帮助。
Hope it helps.
这篇关于如何将ALL添加到从表中填充的下钻列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!