恢复在 c# 中的 GridView1 RowEditing 上设置的 CommandArgument 值

Recovery tha value of CommandArgument set on GridView1 RowEditing in c#

我需要恢复设置在 :

上的 CommandArgument 的值
<ItemTemplate>
   <asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server"
      CommandArgument='<%#Eval("Rec").ToString().Contains("100") ? 1 : 0 %>'
      ImageUrl='<%#Eval("Rec").ToString().Contains("100") ? "~/icon1.gif" : "~/icon0.gif"%>'/>
</ItemTemplate>

GridView1_RowEditing中:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    int SelectRec = int.Parse((sender as ImageButton).CommandArgument);
    GridView1.EditIndex = e.NewEditIndex;
    BindData(); 
}

我尝试添加 GridView1_RowEditing,但没有成功:

int SelectRec = int.Parse((sender as ImageButton).CommandArgument);

如何解决这个问题?

你能帮帮我吗?

提前感谢您的帮助,非常感谢。

试试这个从 GridView1.DataKeys:

中获取 CommandArgumentvalue
int SelectRec = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Value);