簡體   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