Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何使用“删除”按钮获取选定行索引和选定行的单元格值_Asp.net_Linq - Fatal编程技术网

Asp.net 如何使用“删除”按钮获取选定行索引和选定行的单元格值

Asp.net 如何使用“删除”按钮获取选定行索引和选定行的单元格值,asp.net,linq,Asp.net,Linq,我已经在gridview中使用了templete字段删除按钮,因此当我单击gridview中的任何删除按钮删除一行时,它将为删除行索引提供所选行的单元格[0]值。我怎么能让任何人有一个想法 protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); int grdid

我已经在gridview中使用了templete字段删除按钮,因此当我单击gridview中的任何删除按钮删除一行时,它将为删除行索引提供所选行的单元格[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命令删除行获取索引,但它不起作用

您不能这样做,但您必须使用按钮单击事件来选择ID,然后将该ID用作秒的参数,不同的删除查询。

您不能这样做,但必须使用按钮单击事件来选择ID,然后使用该ID作为第二个不同的删除查询的参数。

您可以设置按钮的CommandArgument属性

在Aspx中:

<asp:Button ID="btnDeleteContact" CommandName="DeleteContact" 
CommandArgument="<%# Eval("ContactID") %>" runat="server" >Delete</asp:Button>

希望对您有所帮助

您可以设置按钮的CommandArgument属性

在Aspx中:

<asp:Button ID="btnDeleteContact" CommandName="DeleteContact" 
CommandArgument="<%# Eval("ContactID") %>" runat="server" >Delete</asp:Button>

希望对你有所帮助我找到了这个问题的完美解决方案

    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();

    }  

这段代码在我的模块中正常工作…

我找到了这个问题的完美解决方案

    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();

    }  

此代码在我的模块中正常工作…

但我必须删除同一选定行,还需要从选定行主单元格值中删除另一个表值…是的,您可以使用不同的sql命令变量为同一sql连接下不同表中的两条不同记录编写两个单独的删除查询。但我必须删除同一选定行,还需要从选定行主单元格值中删除另一个表值…是的,您可以使用不同的sql命令变量为同一sql连接下不同表中的两条不同记录编写两个单独的删除查询。Chintan@可能他在asp.net中使用C@可能他在asp.net中使用C