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

How to set enable=false for GridEditCommandColumn,GridButtonColumn?

3 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guruvu
Top achievements
Rank 1
Guruvu asked on 16 Feb 2011, 04:31 AM

Hi,

In my grid i need to set enable= false for GridEditCommandColumn,GridButtonColumn's.Here is my source code:

<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditButton"
                                 HeaderStyle-HorizontalAlign="Left" HeaderText="Edit" 
                                 ItemStyle-HorizontalAlign="Left">
                                 <HeaderStyle HorizontalAlign="Left" />
                                 <ItemStyle HorizontalAlign="Left" />
                             </telerik:GridEditCommandColumn>
  
                             <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="DeleteButton"
                                 ConfirmDialogHeight="100px" ConfirmDialogType="RadWindow" HeaderText="Delete"
                                 ConfirmDialogWidth="220px" 
                                 ConfirmText="Are you sure you want to delete this Indent Item?" ConfirmTitle="Delete" 
                                 HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="NotSet" 
                                 ItemStyle-HorizontalAlign="Left">
                                 <HeaderStyle HorizontalAlign="Left" />
                                 <ItemStyle HorizontalAlign="Left" />
                             </telerik:GridButtonColumn>

I am using below code under PreRender event for the above requirement as below:
protected void gvItems_PreRender(object sender, EventArgs e)
   {
       foreach (GridDataItem item in gvItems.MasterTableView.GetItems(GridItemType.Item))
                {
                   ImageButton btn1 = (ImageButton)item.FindControl("EditButton");//accessing the Button by its name
                   btn1.Enabled = false;                    
                }
   }

Even though it's not working...

Can any one help me...

Thanks in advance...

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 16 Feb 2011, 05:25 AM
Hello,

Try the following code snippet in the Pre-Render Event.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)//setting visibility for each control
  {
      foreach (GridDataItem item in RadGrid1.MasterTableView.GetItems(GridItemType.Item))
      {
          ImageButton btn1 = (ImageButton)item["EditButton"].Controls[0];
          btn1.Enabled = false;
      }
  }

Thanks,
Shinu.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Feb 2011, 05:40 AM
<telerik:GridEditCommandColumn ButtonType="ImageButton"
                    UniqueName="EditButton" HeaderStyle-HorizontalAlign="Left"
                       HeaderText="Edit" ItemStyle-HorizontalAlign="Left">
                       <HeaderStyle HorizontalAlign="Left" />
                       <ItemStyle HorizontalAlign="Left" />
                   </telerik:GridEditCommandColumn>
                   <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="DeleteButton"
                       ConfirmDialogHeight="100px" ConfirmDialogType="RadWindow" HeaderText="Delete"
                       ConfirmDialogWidth="220px" ConfirmText="Are you sure you want to delete this Indent Item?"
                       ConfirmTitle="Delete" HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="NotSet"
                       ItemStyle-HorizontalAlign="Left">
                       <HeaderStyle HorizontalAlign="Left" />
                       <ItemStyle HorizontalAlign="Left" />
                   </telerik:GridButtonColumn>
                   <telerik:GridTemplateColumn UniqueName="disableColumnTest" AllowFiltering="false">
                       <ItemTemplate>
                           <asp:Button ID="btnTest" Text="Test" runat="server" />
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>


protected void gvDiseaseGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
 
        GridDataItem item = (GridDataItem)e.Item;
 
        ImageButton imageButton = (ImageButton)item["EditButton"].Controls[0];
        imageButton.Enabled = false;
 
        ImageButton button = (ImageButton)item["DeleteButton"].Controls[0];
        button.Enabled = false;
 
        Button btnTest = (Button)item["disableColumnTest"].FindControl("btnTest");
        btnTest.Enabled = false;
 
 
    }
    
}


Hi guruvu,

try this code and let me know if still not solve your issue.

Thanks,
Jayesh Goyani
0
Anto
Top achievements
Rank 1
answered on 22 Oct 2016, 12:05 PM

Hi Jayash

Could you please guide me to find the controls text, There are 3 buttons in single tag.

<telerik:GridEditCommandColumn HeaderStyle-Width="50px" ButtonType="ImageButton" UniqueName="UpdateColumn" CancelImageUrl="Images/cancel.png" UpdateImageUrl="Images/accept.png" InsertImageUrl="Images/accept.png" />

Tags
Grid
Asked by
Guruvu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Anto
Top achievements
Rank 1
Share this question
or