这可能有点棘手,所以请耐心等待。
我从gridview获得此结果,数据来自数据透视表:
DateCreate 02/11/2013 02/19/2013 Total
OrdersPendInvoice 0 1 1
OrdersPendPickUp 1 15 16
这里可选择的项目是数字,只有大于零的数字。
所以首先我需要那些项目(可选择的项目)使它们像linkButtons儿子,当我点击其中一个时,我可以作为参考传递(这里是另一个棘手的部分)两个标题。
我们举一个例子:
如果我点击了数字15,这基本上意味着日期为02/19/2013有15个OrdersPendPickUp。然后,我将转到带有参考02/19/2013
和OrdersPendPickUp
的不同页面,并显示这15条记录。只要我有参考文献,我对最后一部分没有任何问题。
对于Total
案例,我只需要OrdersPendInvoice
或OrdersPendPickUp
(取决于所选项目)因为我将获得该参考的所有记录,无论日期。
我做了这个,但实际上并不多,只是改变大于零的项目的颜色:(
protected void gvOrdersProcessed_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Pager)
{
for (int i = 0; i <= e.Row.Cells.Count - 1; i++)
{
if (TryToParse(e.Row.Cells[i].Text) > 0)
{
e.Row.Cells[i].ForeColor = System.Drawing.Color.Red;
}
}
}
}
private int TryToParse(string value)
{
int number;
bool result = Int32.TryParse(value, out number);
if (result)
return number;
else
return 0;
}
答案 0 :(得分:2)
是的,这很棘手。但是,请尝试以下方法:
private List<string> _headers = new List<string>();
protected void gvOrdersProcessed_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Collect the texts from the column headers
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i <= e.Row.Cells.Count - 1; i++)
{
this._headers.Add(e.Row.Cells[i].Text);
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i <= e.Row.Cells.Count - 1; i++)
{
if (TryToParse(e.Row.Cells[i].Text) > 0)
{
string rowKey = e.Row.Cells[0].Text;
string column = this._headers[i];
HyperLink link = new HyperLink();
link.Text = e.Row.Cells[i].Text;
link.NavigateUrl="page.aspx?key=" + rowKey + "&column=" +column;
e.Row.Cells[i].Controls.Clear();
e.Row.Cells[i].Controls.Add(link);
}
}
}
}
链接就像:
正常值: ~/page.aspx?key=OrdersPendPickUp&column=02/19/2013
总计: ~/page.aspx?key=OrdersPendPickUp&column=Total