Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how to access the buttons of Telerik RadGrid

Tags:

c#

I am using Telerik RadGrid, i add a new button in the grid but how can i write an event for this button (Buy) for example when the user press (Buy) it will add this item to his cart with its price in order to calculate his bill. regards

like image 553
user748057 Avatar asked Feb 23 '23 22:02

user748057


2 Answers

You need to listen for the ItemCommand event:

<telerik:GridButtonColumn UniqueName="Buy" ButtonType="LinkButton" 
    Text="Buy" ConfirmText="Add to cart?" 
    OnItemCommand="rg_ItemCommand" CommandName="AddToBasket" />

In your codebehind

protected void rg_ItemCommand(object sender, GridCommandEventArgs e)
{
    if(e.CommandName == "AddToBasket")
    {
        // Add to basket code here
    }
}

You may also need to set the CommandArgument during the ItemCreated or ItemDatabound events, or get it using something like rg.MasterTableView.DataKeyValues[e.Item.Index]["ItemId"].ToString(); after setting ClientDataKeyNames="ItemId" in your MasterTableView settings part in the ascx file (if it is databound).

like image 200
mdm Avatar answered Mar 07 '23 20:03

mdm


You need to use the ItemCommandEvent of grid. The ItemCommand event is raised when a button is clicked in the Telerik RadGrid control. This allows you to provide an event-handling method that performs a custom routine whenever this event occurs. Follow the LINK to have more details.

like image 41
MUS Avatar answered Mar 07 '23 18:03

MUS