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

hide/show GridCheckBoxColumn in ItemDataBound

8 Answers 564 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DJ
Top achievements
Rank 1
DJ asked on 23 Apr 2008, 09:11 PM
I'm trying to determine weather to show or hide the checkbox in a GridCheckBoxColumn inside the grid's ItemDataBound event.  I thought this would be a simple task.

Inside my ItemDataBound method:

if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;

                if (dataItem["ItemTypeName"].Text.Equals("Sponsorship"))
                {
                    CheckBox cb = (CheckBox)dataItem["column"].Controls[0];
                    //cb.Enabled = false;
                    cb.Visible = false;
                    //cb.Checked = true;
                    lbCancelEntireOrder.Visible = false;
                }
            }

the lbCancelEntireOrder.Visible line works - so I know the problem is not in the ItemDataBound itself.  Am I getting the CheckBox out of the column properly?

Thanks

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Apr 2008, 07:38 AM
Hi DJ,

Try the following code snippet to achieve the desired scenario.

CS:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            CheckBox chkbx = (CheckBox)item["column"].Controls[0]; 
            string strtxt = item["ItemTypeName"].Text.ToString(); 
            if (strtxt == "Sponsorship") 
            { 
                chkbx.Visible = false
            } 
        } 
  } 


Thanks
Shinu.
0
DJ
Top achievements
Rank 1
answered on 24 Apr 2008, 01:49 PM
This code is pretty close to what I had - but I did copy it all and paste it into my page with the same results.   The label's visibility is properly set to false, but the checkbox just will not go away.
0
Shinu
Top achievements
Rank 2
answered on 25 Apr 2008, 04:57 AM
Hi Dj,

Can you check whether you have set the correct ColumnUniqueName for the CheckBox Column? Sending your aspx code will be more good.

Thanks
Shinu.

0
DJ
Top achievements
Rank 1
answered on 25 Apr 2008, 01:45 PM
Ok, I removed everything except the UniqueName from the column:

<radG:GridCheckBoxColumn UniqueName="cbCol"
</radG:GridCheckBoxColumn> 

And I've modified my aspx.cs page a little bit:

protected void rdgOrderItems_OnItemDataBind(object sender, Telerik.WebControls.GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                CheckBox chkbx = (CheckBox)item["cbCol"].Controls[0]; 
                string strtxt = item["ItemTypeName"].Text.ToString(); 
                if (strtxt == "Sponsorship") 
                { 
                    chkbx.Visible = false
                    lbCancelEntireOrder.Visible = false
                } 
            } 

The lines that hides lbCancelEntireOrder works - while the line that hides chkbx does nothing. 

What am I doing wrong here, any idea?  Thanks.
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2008, 12:39 PM
Hi DJ,

Could try the same code in the ItemCreated event handler? Try it out  and let me know if this helped.

Thanks,
Shinu

0
DJ
Top achievements
Rank 1
answered on 28 Apr 2008, 07:31 PM
I put the code into an OnItemCreated method and get the same results.

I also tried to loop through all rows in the PreRender of the grid, but that didn't work either.

I'm starting to get really frustrated with this.  Telerik has typically been good to me, but not the GridCheckBoxColumn.
0
Accepted
Yavor
Telerik team
answered on 29 Apr 2008, 06:42 AM
Hello DJ,

Attached to this message is a small application, which handles a functionality close to the one that you mentioned. Take a look at it and let me know if this is the expected behavior.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
DJ
Top achievements
Rank 1
answered on 29 Apr 2008, 02:44 PM
Thanks for the example.  That is pretty much what I was trying to accomplish, but 2 minor differences.

1. My form was put into edit mode so the checkboxes were enabled.

2. My column didn't have a DataType.

I've just removed the whole column instead of tyring to hide individual checkboxes - that is going to work just fine for me.

Thanks
Tags
Grid
Asked by
DJ
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DJ
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or