在C#中的子嵌套gridview中编辑行

问题描述 投票:0回答:1

我需要在嵌套(子)gridview上编辑行。

这是我的代码,但是编辑打开的ID始终相同:

选择*从doTable的sID输入('72')

如何解决此问题?

//On Gridview g1
<asp:TemplateField HeaderText="" Visible="false">
   <ItemTemplate>
      <asp:Label ID="lblsID" Text='<%# Eval("sID") %>' runat="server"></asp:Label>
   </ItemTemplate>
</asp:TemplateField>

protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView g2 = (GridView)sender;
    g2.EditIndex = e.NewEditIndex;

    int customerId = (int)g1.DataKeys[e.NewEditIndex].Value;

    sql = @String.Format(" SELECT * FROM `doTable` ");
    sql += String.Format(" WHERE sID IN ('{0}') ", customerId);

    Response.Write(sql);

    g2.DataSource = GetData(sql);
    g2.DataBind();

}
c# gridview edit
1个回答
1
投票

请尝试这个:

    protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView g2 = (GridView)sender;
        g2.EditIndex = e.NewEditIndex;

        GridViewRow gvCustomerRow = g2.NamingContainer as GridViewRow;
        int customerId = (int)g1.DataKeys[gvCustomerRow.RowIndex].Value;

        sql = @String.Format(" SELECT * FROM `doTable` ");
        sql += String.Format(" WHERE sID IN ('{0}') ", customerId);

        g2.DataSource = GetData(sql);
        g2.DataBind();
    }
© www.soinside.com 2019 - 2024. All rights reserved.