2013-01-03 25 views
0

當我剛剛創造了這個擴展與皮膚GridViewRow:追加的CssClass到數據綁定

public static class GridViewRowExtension 
{ 
    public static void AppendCssClass(this GridViewRow row, string cssClass) 
    { 
     row.CssClass = string.Format("{0} {1}", row.CssClass, cssClass).Trim(); 
    } 
} 

用它OnRowDataBound事件:

protected void OnInstrumentsRowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      AdjustRow(e.Row); 
      ToggleCloseButton(e.Row); 
      DisplayPerformance(e.Row); 
     } 
     else 
     { 
      e.Row.AppendCssClass("nodrag nodrop grt_gridview_default_header"); 
     } 
    } 

但是追加不起作用,因爲排.CssClass用作此行中的{0}:

row.CssClass = string.Format("{0} {1}", row.CssClass, cssClass).Trim(); 

是空的。我期待它會有一個在GridView默認皮膚中定義的CssClass。

我敢肯定,我的皮膚作爲當我刪除AppendCssClass調用我看到在皮膚中定義的CssClass。

任何想法,爲什麼我沒有達到我想要的?

+0

@dragonfly:你這個附加的headerrow? – naveen

+0

在這個特殊的例子中,腳註。但是當我需要根據應用程序邏輯在隨機行上更改CssClass時,我有其他用法。 – dragonfly

回答

0

你爲什麼不試試jQuery的這一點,它可能爲你工作,你想要

$(document).ready(function() 
{$("#divGridView table tbody tr").each(function() 
    { 
    var myClass = $(this).attr("class"); 
    $(this).removeClass(myClass); 
    $(this).addClass(myClass + " nodrag nodrop grt_gridview_default_header"); 

})}); 
+0

謝謝,雖然它不適用於我:我有其他用法,當我需要根據應用程序邏輯在隨機行上更改CssClass時。 – dragonfly