【问题标题】:Get the column names in a GridView with dynamic columns (Pivot query) on row databound使用行数据绑定上的动态列(数据透视查询)获取 GridView 中的列名
【发布时间】:2014-02-14 20:56:27
【问题描述】:

我正在使用 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);
                //}

【问题讨论】:

  • 你用哪一个事件来做这个???
  • OnRowDataBound (GridView1_DataBound(object sender, GridViewRowEventArgs e))

标签: c# asp.net gridview pivot


【解决方案1】:

如果您想在 HTML 代码中使用该值,您可以这样做:

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

希望这能行得通!

【讨论】:

    猜你喜欢
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    相关资源
    最近更新 更多