繁体   English   中英

在GridView上获取具有行数据绑定中的动态列(列查询)的列名

[英]Get the column names in a GridView with dynamic columns (Pivot query) on row databound

我正在使用SQL数据源生成Gridview。 数据源具有一个存储过程,该存储过程使用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"))

希望这能起作用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM