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

[Solved] Programatically hide controls in a data row

2 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 01 Sep 2009, 08:24 AM
Hi,

I'm using the latest version of the Telerik controls and using the RadGrid to show a list of quotations. Dependent on the quote status I want to show/hide linkbuttons for each row depending on which is valid at the time. I have the following columns:

                   <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="View" Text="View Quote" UniqueName="lnkView" />
                   <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="Edit" Text="Edit Quote" UniqueName="EditColumn" />
                   <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="BuyNow" Text="Buy Now" UniqueName="BuyNowColumn" />

in the code behind I'm using grdCarQuotes_ItemCreated and grdCarQuotes_ItemDataBound to try and find the linkbutton controls to set their visibility as so:

        protected void grdCarQuotes_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                // Get car quote status
                string status = ((BLL.DTO.QuoteSummaryRow)e.Item.DataItem).Status;
                LinkButton lnk = e.Item.FindControl("lnkView") as LinkButton;
                if(status != "Quoted")
                          lnk.Visible = false;
            }
        }

However, it can't find the control. Please can you advise me on how to best achieve this simple requirement?

TIA,

Rick

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Sep 2009, 09:30 AM
Hello Rick,

Try out the following code to access the linkbutton in the GridButtonColumn:
c#:
 protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            LinkButton lnk = dataItem["lnkView"].Controls[0] as LinkButton;            
            lnk.Visible = false
        } 
    } 

Thanks
Princy.
0
Rick
Top achievements
Rank 1
answered on 01 Sep 2009, 12:08 PM
Thanks very much, that works!!!
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rick
Top achievements
Rank 1
Share this question
or