简体   繁体   中英

Set an Attribute to the HeaderRow of the Radgrid [telerik] from Code Behind

I have a Radgrid like this in my ASPX page,

   <telerik:RadGrid ID="rGVResults">
          <MasterTableView AllowPaging="false" CellPadding="0" CellSpacing="0"  AllowFilteringByColumn="true" 
                            AllowSorting="true" AllowNaturalSort="false" Width="100%"
                            TableLayout="Auto" Frame="Void" GroupLoadMode="Client">              
          <Columns>
           .
           .
          </Columns>                
          </MasterTableView>
  </telerik:RadGrid>

Now I want to add an attribute to the header row of the radgrid from codebehind(aspx.cs) by doing this,

rGVResults.HeaderRow.Cells[0].Attributes["data-class"] = "expand";

Which works fine for an asp:gridview but not with the telerik radgrid. What am I doing wrong?

Can someone suggest me an alternative?

Try this:

rGVResults.HeaderRow.Cells[0].Attributes.Add("data-class", "expand");

Or try this way

 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
{  
    if (e.Item is GridDataItem)  
    {  
        GridDataItem dataItem = e.Item as GridDataItem;  
        TableCell cell = dataItem["ColumnUniqueName"];  
        cell.Attributes["data-class"] = "expand";  
    }  
} 

You should try this:

rGVResults.HeaderStyle.CssClass = "expand";

The default value is System.String.Empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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