在 GridView 中获取列名称,其中包含行数据绑定上的动态列(透视查询)



我正在使用SQL数据源生成网格视图。 数据源具有一个存储过程,该过程使用 PIVOT 生成基于日期的列名。 我想使每个单元格可单击(基于列中的文本),但找不到列名称。

我尝试了一些方法,例如检查 Row[0]。 理想情况下,我想将基于行的第一列和列标题的单元格值传递给更新面板,但首先我需要知道我正在创建的单元格的列标题文本是什么。

if (e.Row.RowType != DataControlRowType.Header)
    {
        string item = e.Row.Cells[0].Text;
        string column;
        for (int j = 0; j < e.Row.Cells.Count; j++)
        {
            column = GridView1.HeaderRow.Cells[j].Text;
            if (j >= 3)
            {

                e.Row.Cells[j].Font.Italic = true;
                e.Row.Cells[j].Text = e.Row.Cells[j].Text.Replace(".00", "");
                //if (GridView1.HeaderRow.Cells[j].Text.Substring(0,3) == "SKU")
                //{
                    e.Row.Cells[j].Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
                    e.Row.Cells[j].Attributes["onmouseout"] = "this.style.textDecoration='none';";
                    e.Row.Cells[j].ToolTip = "Click to select cell";
                    e.Row.Cells[j].Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
                //}
如果你想

在HTML代码中使用该值,你可以这样做:

     if (String.Equals(((VALUETYPE)e.Row.FindControl("IDCONTROLHTML")).Value.ToString(), "SOMEVALUE"))

希望这有效,伙计!!

最新更新