【问题标题】:get row value on update Button在更新按钮上获取行值
【发布时间】:2018-08-14 19:57:07
【问题描述】:

获取按钮按下的行的产品SKU

protected void On_Update_Click(object sender, EventArgs e)
{
}

【问题讨论】:

    标签: asp.net entity-framework telerik entity-framework-6


    【解决方案1】:

    最简单的方法是使用DataKeyNames 属性。

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="SKU">
    

    然后您可以根据行索引访问正确的 DataKeyNames。

    protected void On_Update_Click(object sender, EventArgs e)
    {
        //cast the sender back to a control and get the gridviewrow from the namingconainer
        GridViewRow row = (GridViewRow)(((Control)sender).NamingContainer);
    
        //get the gridview itself from the gridviewrow
        GridView gv = row.Parent.Parent as GridView;
    
        //get the correct datakey from the gridview with the dataitemindex
        int SKU = Convert.ToInt32(gv.DataKeys[row.DataItemIndex].Values[0]);
    
        //display result
        Label1.Text = SKU.ToString();
    }
    

    【讨论】:

    • 其实我正在使用 Telerik (RadGrid)
    • 啊。我自己不认识 radgrid。但也许它有类似的机制,你可以调整我的答案吗?
    猜你喜欢
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 2020-01-12
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多