在 C# 中编辑子嵌套 gridview 中的行
Editing row in child nested gridview in C#
我需要在嵌套(子)gridview 上编辑行。
这是我的代码,但编辑打开时始终使用相同的 ID :
SELECT * FROM doTable WHERE sID IN ('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();
}
请试试这个:
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();
}
我需要在嵌套(子)gridview 上编辑行。
这是我的代码,但编辑打开时始终使用相同的 ID :
SELECT * FROM doTable WHERE sID IN ('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();
}
请试试这个:
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();
}