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

Grid column Count

3 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muralidharan Ramakrishnan
Top achievements
Rank 1
Muralidharan Ramakrishnan asked on 10 Dec 2008, 10:24 AM
Hi,

We have a radGrid with one pre-defined checkbox column. To this grid we bind a dynamically generated datatable. Based on a certain logic we have to hide some of the columns in the grid. We are using the following code piece

Sub Page-Prerender
grdlist.datasource=databale
grdlist.databind

 

For Each col As Telerik.Web.UI.GridColumn In grdList.Columns

 

 

If col.UniqueName = "Field to Check" Then

 

col.Display =

False

 

 

Exit For

 

 

End If

 

 

Next
end sub

However the Grid seems to have only one column even in the page prerender hence we dont get to access the column at all. Which event must be used to hide a column?

Issue #2

BTW i also see the checkbox column always grayed even though i have given "REadonly" as "false". What we need is to give a user functionality to click the check boxes and click delete / assign.

1. How to enable the checkboxes in the grid
2. How to get the checked items.

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Dec 2008, 10:51 AM
Hi,

I guess the rest of the columns in the your Grid are AutoGenerated. If so you can access the autogenerated columns in the ColumnCreated event and hide the required columns.

GridCheckBoxColumn will render CheckBox as disabled in normal mode and it will be enabled only in edit mode. One suggestion will be to use a GridTemplateColumn with a CheckBox in its ItemTemplate.
Column types

Thanks
Shinu.
0
Muralidharan Ramakrishnan
Top achievements
Rank 1
answered on 10 Dec 2008, 11:01 AM
Thanks for the quick response. I am able to hide the columns now. How to get the checked items though?
0
Princy
Top achievements
Rank 2
answered on 10 Dec 2008, 11:57 AM
Hi,

You can access the CheckBox value for a GridCheckBox Column in the ItemDataBound event as shown below.

ASPX:
<telerik:GridCheckBoxColumn UniqueName="CheckCol" DataField="CheckCol"  HeaderText="CheckCol" ></telerik:GridCheckBoxColumn> 

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            CheckBox chkbx = (CheckBox)item["CheckCol"].Controls[0]; 
            if (chkbx.Checked) 
            { 
                string strtxt = item["columnUniqueName"].Text; 
            } 
        } 
    } 


Princy.
Tags
Grid
Asked by
Muralidharan Ramakrishnan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Muralidharan Ramakrishnan
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or