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

OnClientClicked GridButtonColumn

4 Answers 359 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 23 Sep 2013, 02:16 PM
How implement "OnClientClicked" to GridButtonColumn?

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 24 Sep 2013, 03:56 AM
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
0
Travis Richardson
Top achievements
Rank 1
answered on 27 Feb 2019, 05:34 PM

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

0
Marin Bratanov
Telerik team
answered on 04 Mar 2019, 12:57 PM
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.
0
Travis Richardson
Top achievements
Rank 1
answered on 04 Mar 2019, 02:40 PM
Ah yes, 'Button Type'.  Well that seems obvious now!  Thanks.
Tags
Grid
Asked by
Kjell
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Travis Richardson
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or