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

GridCheckBoxColumn with Y N value

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lenny_shp
Top achievements
Rank 2
Lenny_shp asked on 22 Dec 2009, 03:07 PM
Is it possible to utilize GridCheckBoxColumn if the underlying datafield value stores string Y and N instead of 1 and 0?
I would like to display a read only version of the checkbox that is still legible.   If I use the template to set it to Enabled="false", it's very light.  (and the GridTemplateColumn's ReadOnly property doesn't work)

                    <telerik:GridTemplateColumn UniqueName="emailprimaryuser" HeaderText="Email Primary User"  
                        ReadOnly="true" DataField="emailprimaryuser" SortExpression="emailprimaryuser"
                        <ItemTemplate>  
                            <asp:CheckBox Enabled="false" ID="chkemailprimaryuser" runat="server" Checked='<%# DataBinder.Eval (Container.DataItem,"emailprimaryuser").ToString()="Y" %>' 
                             /> 
                        </ItemTemplate>                                                   
                    </telerik:GridTemplateColumn>    

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 23 Dec 2009, 06:08 AM
Hi,

The best approach would be to use a GridTemplateColumn with a disabled CheckBox control inside its ItemTemplate.
But if you want to use a GridCheckBoxColumn, then you could set the DataKeyName attribute of the MasterTableView to the DataField to which you want to bind the checkbox. Access the checkbox and then set its checked property to true depending on the DataKeyValue. Here's an example:
aspx:
 <telerik:radgrid id="RadGrid1"AutoGenerateColumns="False" DataSourceID="SqlDataSource1" runat="server" >        
    <MasterTableView DataKeyNames="Approved" DataSourceID="SqlDataSource1">         
      <Columns>         
       <telerik:GridCheckBoxColumn UniqueName="Check">        
       </telerik:GridCheckBoxColumn> 
        ..... 

cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if(e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            CheckBox chk = (CheckBox)dataItem["Check"].Controls[0]; 
            string strtxt = dataItem.GetDataKeyValue("Approved").ToString();           
            if (strtxt == "Y") 
                chk.Checked = true
            else 
                chk.Checked = false
        } 
   } 

Hope this helps..
Princy.
Tags
Grid
Asked by
Lenny_shp
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Share this question
or