How to set enable=false for GridEditCommandColumn,GridButtonColumn?

4 posts, 0 answers
  1. guruvu
    guruvu avatar
    32 posts
    Member since:
    Sep 2010

    Posted 15 Feb 2011 Link to this post

    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...
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Feb 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 15 Feb 2011 Link to this post

    <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
  5. Anto
    Anto avatar
    1 posts
    Member since:
    Oct 2016

    Posted 22 Oct Link to this post

    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" />

Back to Top