We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Grid - status column want to show different font color and different backgrod color

Hi

load / add /edit grid record status column ,how to show different font color and different background color ?

status - completed,new,process

private void BindDataSource()

{

if ((List<Products>)Session["DialogDataSource"] == null)

{

product.Add(new Products(10001, "ALFKI","completed"));

product.Add(new Products(10002, "ANATR", "new"));

product.Add(new Products(10003, "WERSDD", "process"));

}

else

{

product = (List<Products>)Session["DialogDataSource"];

}

this.ProductGrid.DataSource = product;

this.ProductGrid.DataBind();

}


protected void EditAction(string eventType, object record)

{

List<Products> data = Session["DialogDataSource"] as List<Products>;

Dictionary<string, object> KeyVal = record as Dictionary<string, object>;

if (eventType == "endEdit")

{

Products value = new Products();

foreach (KeyValuePair<string, object> keyval in KeyVal)

{

if (keyval.Key == "Productcode")

{

value = data.Where(d => d.Productcode == (int)keyval.Value).FirstOrDefault();

value.Productcode = Convert.ToInt32(keyval.Value);

}

else if (keyval.Key == "Productname")

value.Productname = Convert.ToString(keyval.Value);

else if (keyval.Key == "status")

value.status = Convert.ToString(keyval.Value);

}

}

else if (eventType == "endAdd")

{

Products newRecord = new Products();

foreach (KeyValuePair<string, object> keyval in KeyVal)

{

if (keyval.Key == "Productcode")

newRecord.Productcode = Convert.ToInt32(keyval.Value);

else if (keyval.Key == "Productname")

newRecord.Productname = Convert.ToString(keyval.Value);

else if (keyval.Key == "status")

newRecord.status = Convert.ToString(keyval.Value);

}

data.Insert(0, newRecord);

}

else if (eventType == "endDelete")

{

foreach (KeyValuePair<string, object> keyval in KeyVal)

{

if (keyval.Key == "Productcode")

{

Products value = data.Where(d => d.Productcode == (int)keyval.Value).FirstOrDefault();

data.Remove(value);

}

}

}

Session["DialogDataSource"] = data;

this.ProductGrid.DataSource = data;

this.ProductGrid.DataBind();

}


Thanks
Pratheep




Attachment: WebApplication1_2e767a9c.rar

3 Replies

MS Mani Sankar Durai Syncfusion Team January 2, 2017 12:05 PM UTC

Hi Pratheep, 

Thanks for contacting Syncfusion support, 

We have analyzed your query and we can achieve your requirement by using QueryCellInfo event in grid. We have also prepared a sample that can be downloaded from the below link. 


Please refer the below code example. 

[workorder.aspx] 
  <ej:Grid ID="ProductGrid" ClientIDMode="Static" runat="server" AllowPaging="True" AllowFiltering="false" OnServerEditRow="EditEvents_ServerEditRow" 
                    OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow"> 
                  
  <ClientSideEvents ActionComplete="complete" QueryCellInfo="querycellinfo"  EndAdd="endAdd" EndDelete="endDelete" EndEdit="endEdit" /> 
                                      <Columns> 
                   
</Columns> 
                         ... 
                </ej:Grid>            
 
<script type="text/javascript"> 
        function querycellinfo(args) { 
            var grid = $('#<%= ProductGrid.ClientID %>').ejGrid("instance"); 
            if (args.text == "completed") { 
                args.cell.style.color = "black"; 
                args.cell.style.background = "orange"; 
            } 
            else if (args.text == "new") { 
                args.cell.style.color = "white"; 
                args.cell.style.background = "green"; 
             ... 
            }  
        } 
</script> 

From the above code example we have changed the background color and particular text color using queryCellInfo event in grid. 
Please refer the documentation link. 
  
Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 



PR Pratheep January 3, 2017 12:39 AM UTC

Hi Manisankar Durai

Thank you for your support.Working fine

Thanks
Pratheep




MS Mani Sankar Durai Syncfusion Team January 3, 2017 06:43 AM UTC

Hi Pratheep, 

Thanks for your feedback. 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Live Chat Icon For mobile
Up arrow icon