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

Enable/Disable telerik:GridButtonColumn

1 Answer 1085 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
reza
Top achievements
Rank 1
reza asked on 02 Nov 2012, 05:01 PM
Hi
Is it possible to enable/disable icons of telerik:GridButtonColumn in grid rows?
I want to disable "delete icon" for some grid rows through binding expression (or by OnItemDataBound) . 
&
Why this type of column does not support binding expression for
CommandArgument
?
Thank you very much.

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Nov 2012, 02:31 PM
Hello,

Please try with below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
           OnItemDataBound="RadGrid1_ItemDataBound" >
           <MasterTableView DataKeyNames="ID" >
               <Columns>
                   <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                   </telerik:GridBoundColumn>
                   <telerik:GridButtonColumn ButtonType="ImageButton" ImageUrl="~/tempdata/Myphoto.jpg" UniqueName="deleteColumn"
                    CommandName="Delete">
                   </telerik:GridButtonColumn>
                   
               </Columns>
           </MasterTableView>
          
       </telerik:RadGrid>

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = e.Item as GridDataItem;
 
               // Get DataKey - disable image from first row
               string strKey = item.GetDataKeyValue("ID").ToString();
               if (strKey == "1")
               {
                   (item["deleteColumn"].Controls[0] as ImageButton).Enabled = false;
               }
 
               // Get ColumnValue -- disable image from second row
               string strName = item["Name"].Text;
               if (strName == "bbb")
               {
                   (item["deleteColumn"].Controls[0] as ImageButton).Enabled = false;
               }
                
           }
 
            
            
 
 
       }
 
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
             new { ID = 1, Name ="aaa"},
             new { ID = 2, Name = "bbb"},
             new { ID = 3, Name = "ccc"},
             new { ID = 4, Name = "ddd"},
              new { ID = 5, Name ="eee"},
              new { ID = 6, Name ="aaa"},
             new { ID = 7, Name = "bbb"},
             new { ID = 8, Name = "ccc"},
             new { ID = 9, Name = "ddd"},
              new { ID = 10, Name ="eee"}
           };
           RadGrid1.DataSource = data;
       }

Thanks,
Jayesh Goyani
Tags
General Discussions
Asked by
reza
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or