This is a migrated thread and some comments may be shown as answers.

[Solved] accessing the value of checkbox column

5 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Afendi Hamat
Top achievements
Rank 1
Afendi Hamat asked on 25 Jun 2008, 04:39 AM
hi all,
heres my table: ProductID(int), ProductName(varchar) and ProductStatus(bit).

I managed to show them all in radgrid.
My question is how to change the formatting/css of a particular row if  its ProductStatus value is False or 0.
I assume its in the item_created event?

thanks in advance for any help.

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Jun 2008, 05:55 AM
Hi,

Check out the following help article which explains how to do conditional row formatting.
Conditional Formatting for rows/cells on ItemDataBound

Shinu.
0
Afendi Hamat
Top achievements
Rank 1
answered on 25 Jun 2008, 06:28 AM
thanks shinu, i still couldnt get it to work. here's my code as copied and modified from the sample you pointed to.

If (TypeOf e.Item Is GridDataItem) Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) 
            If (dataItem("ProductStatus").Text = "False") Then 
                dataItem.CssClass = "style2" 
            End If 
 
        End If 

Thanks.
0
Princy
Top achievements
Rank 2
answered on 25 Jun 2008, 06:55 AM
Hi,

Have you set the CssClass in the aspx page?

ASPX:
<style type="text/css">  
 
 .style2  
 {  
   background-color: aqua;  
   font-size: 16px;  
   fond-family: Arial;  
 }  
</style> 
 

VB:
If (TypeOf e.Item Is GridDataItem) Then    
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)    
            If (dataItem("ProductStatus").Text = "False") Then    
                dataItem.CssClass = "style2"    
            End If    
    
        End If    
 


Princy.
0
Afendi Hamat
Top achievements
Rank 1
answered on 25 Jun 2008, 07:09 AM
yes i did.
is it because the ProductStatus is a gridcheckboxcolumn?

Ok. got it. i changed it to gridboundcolumn and it works. thanks to u both.
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2008, 11:27 AM
Hi,

You can achieve this with GridCheckBoxColumn also. Here is the code snippet:

CS:
  protected void Grid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            CheckBox chkbx = (CheckBox)item["ColumnUniqueName"].Controls[0];  
            if (chkbx.Checked == false)  
            {  
                item.CssClass = "MyStyle";  
            }  
 
        }  
    }  
 


<head runat="server">  
    <title>Untitled Page</title> 
    <style type="text/css" > 
      .MyStyle  
      {  
       background-color:Red !important;  
      }  
    </style> 
</head> 


Thanks
Princy.

Tags
Grid
Asked by
Afendi Hamat
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Afendi Hamat
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or