1
删除的GridView行没有查询有我的GridView我怎么能在DB
<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);
}
但几秒钟后,我得到
此网页不可用
我该怎么做?
有我的数据源。我想删除行,而不删除记录在数据库
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();
我会想象你得到一个计算器,因为你的'Grid_RowDeleting '每次通过'Grid.DeleteRow(index)'命令都会被调用。你应该从你的DataSource/DataTable中删除数据。所以在这种情况下,你的代码的这一部分在Grid.DeleteRow(index)之后缺少给出有意义的答案 – Icepickle 2015-02-09 12:22:40
;再次绑定你的GridView ...检查它........例如Grid.DataBind(); – 2015-02-09 12:27:19
@ Pranav-BitWiser结果相同 – user4523894 2015-02-09 12:28:26