简体   繁体   中英

Get RadGrid row value through a button column in the grid

I have a column with a button in my radgrid, I want to be able to click the button and get the values of the row in which the button is located on. This must be done without selecting the row, I remember seeing a part of code my friend wrote in which he used ".Parent" or something similar to get the row from of the button column clicked.

When you click any button in the GridButtonColumn of a RadGrid, you can access the button's row and the row's values by doing the following:

In the RadGrid's definition, add OnItemCommand="RadGrid1_ItemCommand" .

In the GridButtonColumn's definition, set its command name with something like CommandName="Test" .

Now add the following to your code-behind to access whatever column you want. In my sample code below I get the value in the column "Whatever":

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Test")
    {
        GridDataItem item = (GridDataItem)e.Item;
        string columnWhateverValue = item["Whatever"].Text;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM