简体   繁体   中英

How to disable Telerik radgrid hyperlink column when a specific condition is true

I have a Telerik Radgrid. I want to disable hyperlink columns on page load event when a specific condition is true. I get role id from the database and on the basis of role id want to disable hyperlink columns on page load event. my code is here

if(RoleId==3)  
{  
btnsave.Enabled= false;

  foreach(griddataitem item in RagGrid1.Items)  
   {  
     HyperLink edit = (hyperlink)item["EditHyperLinkColumn"].Controls[0];  
     edit.Enabled = false;  
   }  
}    

when the page loads it gets the role id but did not go inside the foreach statement. Please help.thanks in advance...

Where did you put your foreach loop in? In Page_Load method? This may not work because RadGrid has its own life cycle and events happen in particular sequence.

What you can do instead is to apply your condition in ItemDataBound event.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
{ 
   if (e.Item is GridDataItem) 
   { 
      var item = (GridDataItem)e.Item; 
      var editlink = item.FindControl("EditHyperLinkColumn") as HyperLink;
      if (editlink != null)
      {
          editlink.Enabled = false;
      }
   } 
} 

You need to get the items in the MasterTableView. Also, verify the UniqueName of the Hyperlink Column. Is it actually "EditHyperLinkColumn"?

if(RoleID == 3)
{
    btnsave.Enabled = false;
    foreach(GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        HyperLink edit = (HyperLink)item["EditHyperLinkColumn"].Controls[0];
        edit.Enabled = false;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM