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

Displaying an edit button based on column status

3 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 19 May 2010, 10:10 AM
Hi,

I have a grid that displays a list of all the nominations.  One of the columns displays the status of the nomination.  If this nomination has a status of approved, then it must ONLY display the text Approved.  If the status is Pending, then this colum must display an Edit button to be able to modify this record.  The edit button must only be displayed when the status is pending.  If the status is approved then the edit button must not be displayed.

Is there a sample like this some where?

Thanks
Brendan

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 May 2010, 11:11 AM
Hello Brendan,

You can try the following code snippet to make the edit button visible/invisible based on your column value.

ASPX:
 <Columns> 
         <telerik:GridBoundColumn DataField="Status" HeaderText="Nomination Status" UniqueName="Status_Column" /> 
         <telerik:GridEditCommandColumn UniqueName="EditButton"
         </telerik:GridEditCommandColumn> 
 </Columns> 

C#:
  
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item["Status_Column"].Text == "Approved"
            { 
                LinkButton editbtn = (LinkButton)item["EditButton"].Controls[0]; 
                editbtn.Visible = false
            } 
        } 
    } 

Regards,
Shinu.

0
Brendan Vogt
Top achievements
Rank 1
answered on 30 May 2010, 09:56 AM
Hi,

Thanks for the answer.  This piece of code does not work, it tells me that it cannot find Status_Column.  Here is the error: "Cannot find a cell bound to column name 'Status_Column'".

The row is in the detail table.
0
Princy
Top achievements
Rank 2
answered on 01 Jun 2010, 10:59 AM
Hello Brendan,

If the row is in DetailTable, then in ItemDataBound event you have to check with the name of DetailTable. Check out the following code snippet.

ASPX:
  <DetailTables > 
      <telerik:GridTableView Name="GridTableView1" runat="server" ..........> 


C#:
  
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "GridTableView1"//check with name of DetailTable 
        {  
            GridDataItem item = (GridDataItem)e.Item; 
            if (item["Status_Column"].Text == "Approved"
            { 
                LinkButton editbtn = (LinkButton)item["EditButton"].Controls[0]; 
                editbtn.Visible = false
            } 
        }  
     } 

Thanks
Princy.
Tags
Grid
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brendan Vogt
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or