Search code examples
c#asp.nettelerik

how to get a value from a row in a GridView on Delete Button


See this Photo Plz Grid Photo

Here's the Delete button Function

    protected void Delete_Click(object sender, EventArgs e)
    {
        RadButton btn = (RadButton)sender;
        GridDataItem data = (GridDataItem)btn.NamingContainer;
        string name= data["Name"].Text;

        Label1.Text = name;
     }

Solution

  • I need more information on what your model looks like to be 100% on this, but you should be able to get the DataContext from the clicked item.

    protected void Delete_Click(object sender, EventArgs e)
    {
        var sendr = sender as RadioButton;
        if (sendr != null)
        {
            var clickedItem = sendr.DataContext as YourModel;
            if (clickedItem != null)
            {
                Label1.Text = clickedItem.Name;
            }
        }
    }