我创建了一个没有任何数据键的gridview。我想删除一个gridview行。我需要做些什么改变?
我在C#中使用LINQ。
gridview的HTML是
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateDeleteButton="True" OnRowDeleting="GridView1_RowDeleting"
>
它具有3个绑定字段。
cs代码后面是
protected void GetData()
{
tempcartDataContext tdc = new tempcartDataContext();
var x = (from i in tdc.tempcarts
join k in tdc.GetTable<Medicine>()
on i.MedId equals k.MedId
select new
{
k.Mname,
k.Mprice,
i.Quantity,
k.Mpicture,
}).ToList();
GridView1.DataSource = x;
GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string mname = // expected code to fetch index
var x = (from i in tcdc.tempcarts where i.Mname ==mname select i).SingleOrDefault();
tcdc.tempcarts.DeleteOnSubmit(x);
tcdc.SubmitChanges();
GridView1.EditIndex = -1;
GetData();
}
我希望有一个可以删除行的rowindex。表tempcart中的MedId字段是外键,是表Medicine中的主键