OnClientClicked GridButtonColumn

5 posts, 0 answers
  1. Kjell
    Kjell avatar
    225 posts
    Member since:
    May 2011

    Posted 23 Sep 2013 Link to this post

    How implement "OnClientClicked" to GridButtonColumn?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Sep 2013 Link to this post

    Hi ,

    Please try the following code snippet to raise the Client Event on GridButtonColumn.

    ASPX:
    <telerik:GridButtonColumn UniqueName="GridButtonColumn" ButtonType="PushButton">
    </telerik:GridButtonColumn>

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               Button btn = (Button)item["GridButtonColumn"].Controls[0];
               btn.Attributes.Add("OnClick", "OnClicks(" + btn.ClientID + ");return false;");
           }
       }

    JS:
    <script type="text/javascript">
        function OnClicks(id) {
           //Your Code
        }
    </script>

    Thanks,
    Princy
  3. Travis Richardson
    Travis Richardson avatar
    2 posts
    Member since:
    Jan 2010

    Posted 27 Feb 2019 in reply to Princy Link to this post

    That doesn't work for me.  I get:  Unable to cast object of type 'GridButtonColumnImageButton' to type 'System.Web.UI.WebControls.Button'.

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5807 posts

    Posted 04 Mar 2019 Link to this post

    Hello Travis,

    The ButtonType property of the column determines what type of control is used. If you don't know what that will be, you should add some defensive type checks.

    Also, if you want full control over the code, you should use a template column - you can add your own button there with the desired logic, and command name, and appearance.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Travis Richardson
    Travis Richardson avatar
    2 posts
    Member since:
    Jan 2010

    Posted 04 Mar 2019 in reply to Marin Bratanov Link to this post

    Ah yes, 'Button Type'.  Well that seems obvious now!  Thanks.
Back to Top