Intersoft Support Center

Create Custom Row Format

WebGrid provides FormatConditions feature to help you create your own format for the information/data in WebGrid.

In this topic, you will learn how to create FormatConditions in specific row and cell using table Customers from NorthWind database.

To create FormatConditions in a specific row and cell

  1. Drag WebGrid control from Toolbox to the WebForm.
  2. Switch to code-behind and  Add InitializeLayout server side event:
    C# Copy ImageCopy Code
    using System.Drawing;
    using ISNet.WebUI.WebGrid; 
    
    private void WebGrid1_InitializeLayout(object sender, ISNet.WebUI.WebGrid.LayoutEventArgs e)
    {    
       //specific row     
       WebGridFormatCondition a = new WebGridFormatCondition();     
       a.ColumnMember = "Country";     
       a.ConditionText = "UK";     
       a.Name = "Format1";
       a.FormatStyle.ForeColor = Color.Red;     
       a.TargetObject = ISNet.WebUI.WebGrid.TargetObjectType.Row;         
    
       //specific Cell     
       WebGridFormatCondition b = new WebGridFormatCondition();     
       b.ColumnMember = "City";     
       b.ConditionText = "Madrid";     
       b.Name = "Format2";     
       b.TargetColumnMember = "City";     
       b.FormatStyle.Font.Bold = true;     
       b.TargetObject = ISNet.WebUI.WebGrid.TargetObjectType.Cell;       
    
       WebGrid1.RootTable.FormatConditions.Add(a);     
       WebGrid1.RootTable.FormatConditions.Add(b);
    }     
    

  3. Run the project. The result will look like following.
Please note that if you are using RetrieveStructure, then you need to put the above codes in PrepareDataBinding.
Previous Next