Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > hide/show GridCheckBoxColumn in ItemDataBound

Answered hide/show GridCheckBoxColumn in ItemDataBound

Feed from this thread
  • DJ avatar

    Posted on Apr 23, 2008 (permalink)

    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

    Reply

  • Posted on Apr 24, 2008 (permalink)

    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.

    Reply

  • DJ avatar

    Posted on Apr 24, 2008 (permalink)

    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.

    Reply

  • Posted on Apr 24, 2008 (permalink)

    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.

    Reply

  • DJ avatar

    Posted on Apr 25, 2008 (permalink)

    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.

    Reply

  • Posted on Apr 28, 2008 (permalink)

    Hi DJ,

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

    Thanks,
    Shinu

    Reply

  • DJ avatar

    Posted on Apr 28, 2008 (permalink)

    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.

    Reply

  • Answer Yavor Yavor admin's avatar

    Posted on Apr 29, 2008 (permalink)

    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
    Attached files

    Reply

  • DJ avatar

    Posted on Apr 29, 2008 (permalink)

    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

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > hide/show GridCheckBoxColumn in ItemDataBound
Related resources for "hide/show GridCheckBoxColumn in ItemDataBound"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]