我如何在没有数据库查询的情况下删除 gridview 中的行
how I can delete row in gridview without queries in DB
这是我的gridview
<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="false" AutoGenerateEditButton="true"
ForeColor="#333333" Width="600px" OnRowEditing="Grid_RowEditing" OnRowDeleting="Grid_RowDeleting"
OnRowUpdating="Grid_RowUpdating" OnRowDeleted="Grid_RowDeleted" OnRowCancelingEdit="Grid_RowCancelingEdit"
ShowFooter="True" DataKeyNames="id">
<Columns>
<asp:CommandField ShowDeleteButton="true" />
<asp:CommandField ShowInsertButton="true" ShowHeader="true" />
<asp:BoundField ReadOnly="true" DataField="ProductID" HeaderText="ProductID" NullDisplayText="sad" />
<asp:BoundField ReadOnly="true" DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" />
<asp:BoundField DataField="UnitPrice" HeaderText="TotalPrice" />
</Columns>
</asp:GridView>
我想用这个方法删除行
protected void Grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
Grid.DeleteRow(index);
}
但几秒钟后我得到
This webpage is not available
我该怎么办?
这是我的数据源。我想删除行而不删除 db
中的记录
var query =
from order in mydb.Order_Details
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on order.ProductID equals product.ProductID
where order.OrderID==editOrderID
select new
{
ProductID = order.Product.ProductID,
ProductName = order.Product.ProductName,
Quantity = order.Quantity,
UnitPrice = order.UnitPrice
}
into f
group f by f.ProductID;
var outputData = query.Select(g => new
{
id= g.Key,
ProductID = g.FirstOrDefault().ProductID,
ProductName = g.FirstOrDefault().ProductName,
Quantity = g.FirstOrDefault().Quantity,
UnitPrice = g.FirstOrDefault().UnitPrice
});
Grid.DataSource = outputData;
Grid.DataBind();
您可以在 RowDeleting 事件中创建该行 invisible
,而不是从 UI 中删除 -
GridView1.rows[i].visible=false;
这是我的gridview
<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="false" AutoGenerateEditButton="true"
ForeColor="#333333" Width="600px" OnRowEditing="Grid_RowEditing" OnRowDeleting="Grid_RowDeleting"
OnRowUpdating="Grid_RowUpdating" OnRowDeleted="Grid_RowDeleted" OnRowCancelingEdit="Grid_RowCancelingEdit"
ShowFooter="True" DataKeyNames="id">
<Columns>
<asp:CommandField ShowDeleteButton="true" />
<asp:CommandField ShowInsertButton="true" ShowHeader="true" />
<asp:BoundField ReadOnly="true" DataField="ProductID" HeaderText="ProductID" NullDisplayText="sad" />
<asp:BoundField ReadOnly="true" DataField="ProductName" HeaderText="ProductName" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" />
<asp:BoundField DataField="UnitPrice" HeaderText="TotalPrice" />
</Columns>
</asp:GridView>
我想用这个方法删除行
protected void Grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
Grid.DeleteRow(index);
}
但几秒钟后我得到
This webpage is not available
我该怎么办?
这是我的数据源。我想删除行而不删除 db
中的记录var query =
from order in mydb.Order_Details
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on order.ProductID equals product.ProductID
where order.OrderID==editOrderID
select new
{
ProductID = order.Product.ProductID,
ProductName = order.Product.ProductName,
Quantity = order.Quantity,
UnitPrice = order.UnitPrice
}
into f
group f by f.ProductID;
var outputData = query.Select(g => new
{
id= g.Key,
ProductID = g.FirstOrDefault().ProductID,
ProductName = g.FirstOrDefault().ProductName,
Quantity = g.FirstOrDefault().Quantity,
UnitPrice = g.FirstOrDefault().UnitPrice
});
Grid.DataSource = outputData;
Grid.DataBind();
您可以在 RowDeleting 事件中创建该行 invisible
,而不是从 UI 中删除 -
GridView1.rows[i].visible=false;