.net Webform GridView生成thead

 
GridView控件預設生成是直接tbody包覆
而在套用前端視覺雛形時候可能就會有尷尬沒有thead th可抓到並套用css class style的窘境
若要強迫GridView render出thead th則可透過註冊DataBound Event並撰寫如下邏輯

1
2
3
4
if (GridView1.Rows.Count > 0)
{
    GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}


如果是有包覆UpdatePanel就在更早之前PreRender先寫
而當沒有辦筆資料時候可能要改寫為如下方式才會強制render出thead部分

1
2
3
4
5
6
7
protected void gv1_PreRender(object sender, EventArgs e)
    {
        if (gv1.HeaderRow != null)
        {
            gv1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
    }







Ref:


留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題