有我的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);
}
但几秒后我得到了
此网页不可用
我应该怎么做?
有我的数据源。我想删除行而不删除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();
答案 0 :(得分:0)
您可以在RowDeleting事件中创建该行invisible
-
GridView1.rows[i].visible=false;