我在gridview中使用了模板字段删除按钮,因此当我单击gridview中的任何删除按钮以删除当时的行时,它将为删除行索引提供所选行的cells[0]
值。我怎么能做任何一个有想法....?
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
int grdid = Int32.Parse(GridView3.Rows[index].Cells[0].Text);
IndiesProductDataContext ip = new IndiesProductDataContext();
ip.iLinks.DeleteAllOnSubmit(ip.iLinks.Where(c => c.ProductID == grdid));
ip.SubmitChanges();
}
我在gridview中使用row命令删除行geting索引但它不起作用
答案 0 :(得分:5)
您可以设置按钮
的CommandArgument属性在Aspx:
<asp:Button ID="btnDeleteContact" CommandName="DeleteContact"
CommandArgument="<%# Eval("ContactID") %>" runat="server" >Delete</asp:Button>
在GridView的_RowCommand事件中:
If e.CommandName = "DeleteContact" Then
Dim objContacts As New CContacts
objContacts.ContactID = e.CommandArgument
objContacts.DomainID = Session("DomainID")
Dim strError As String = objContacts.DelContact()
End If
希望有所帮助
答案 1 :(得分:1)
我找到了这个问题的完美解决方案......
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow gvr = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int RowIndex = gvr.RowIndex;
int ci = Int32.Parse(GridView3.Rows[RowIndex].Cells[1].Text);
ProductDataContext ip = new ProductDataContext();
ip.iLinks.DeleteAllOnSubmit(ip.iLinks.Where(c => c.PID == ci));
ip.SubmitChanges();
}
此代码在我的模块中正常运行...
答案 2 :(得分:0)
你不能这样做但你必须使用按钮点击事件来选择ID,然后使用该ID作为第二个不同删除查询的参数。