如何从“删除”按钮上的GridView中的一行中获取值

时间:2018-08-11 18:51:45

标签: c# asp.net telerik

查看此照片Plz Grid Photo

这是“删除”按钮功能

    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;
     }

1 个答案:

答案 0 :(得分:1)

我需要更多有关您的模型达到100%的样子的信息,但是您应该能够从点击的项目中获得DataContext

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;
        }
    }
}