C# 将id从gridview捕获到fillgridview

C# 将id从gridview捕获到fillgridview,c#,asp.net,gridview,categories,rowcommand,C#,Asp.net,Gridview,Categories,Rowcommand,我在一个页面上有两个gridview。。我列出了第一个,而不是从commandargument(“id”)中列出了第二个。。但是我正在这些gridview上做一些事情,我可以实现第一个gridview,因为不需要捕捉id来列出它。它列出了它所拥有的一切。但第二个,我只想列出该产品的类别。你能帮助我吗?以及词语的翻译 Doldur:Fill/GUNCELE:Update/Sil:Delete/vazgec:Cancel 错误的地方满是问号。谢谢你的帮助 private void Dold

我在一个页面上有两个gridview。。我列出了第一个,而不是从commandargument(“id”)中列出了第二个。。但是我正在这些gridview上做一些事情,我可以实现第一个gridview,因为不需要捕捉id来列出它。它列出了它所拥有的一切。但第二个,我只想列出该产品的类别。你能帮助我吗?以及词语的翻译

Doldur:Fill/GUNCELE:Update/Sil:Delete/vazgec:Cancel

错误的地方满是问号。谢谢你的帮助

     private void Doldur()
    {
        WebHelper.FillGridView(myGrid, Service.GetAllCategories());
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;

        Doldur();
    }


    protected void myGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = null;

        if (e.CommandSource is ImageButton)
        {
            row = ((e.CommandSource as ImageButton).NamingContainer) as GridViewRow;
        }

        int id = 0;

        int.TryParse(e.CommandArgument.ToString(), out id);

        switch (e.CommandName)
        {
            case "sil":
                Service.Sil(id);
                break;
            case "guncelle":
                // textbox'ı yakalamak için
                TextBox txtKategoriAd = myGrid.Rows[row.RowIndex].FindControl("txtKategoriAd") as TextBox;
                var kategori = new Categories { CategoryID = id, CategoryName = txtKategoriAd.Text };
                Service.Update(kategori);
                // Edit moddan çıkılmalı..
                myGrid.EditIndex = -1;
                break;
            case "vazgec":
                myGrid.EditIndex = -1;
                break;
            case "link":
                int categoryId = Convert.ToInt32(e.CommandArgument);
                myGrid2.DataSource = Service.GetProductsByCategories(categoryId);
                myGrid2.DataBind();
                break;
        }

        Doldur();
    }
    protected void myGrid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        myGrid.EditIndex = e.NewEditIndex;
        Doldur();
    }

    private void Doldur2()
    {
        WebHelper.FillGridView(myGrid2, Service.GetProductsByCategories(??????));
    }

    protected void myGrid2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = null;

        if (e.CommandSource is ImageButton)
        {
            row = ((e.CommandSource as ImageButton).NamingContainer) as GridViewRow;
        }

        int id = 0;

        int.TryParse(e.CommandArgument.ToString(), out id);

        switch (e.CommandName)
        {
            case "sil2":
                Service.Sil2(id);
                break;
            case "guncelle2":
                // textbox'ı yakalamak için
                TextBox txtKategoriAd2 = myGrid2.Rows[row.RowIndex].FindControl("txtKategoriAd2") as TextBox;
                var product = new Products { ProductID = id, ProductName = txtKategoriAd2.Text };
                Service.Update2(product);
                // Edit moddan çıkılmalı..
                myGrid2.EditIndex = -1;
                break;
            case "vazgec2":
                myGrid2.EditIndex = -1;
                break;
        }

        Doldur2();
    }
    protected void myGrid2_RowEditing(object sender, GridViewEditEventArgs e)
    {
        myGrid2.EditIndex = e.NewEditIndex;
        Doldur2();
    }
}

您应该为第二个网格保存类别id

case "link":
                int categoryId = Convert.ToInt32(e.CommandArgument);
                Session["CategoryID"] = categoryId;
                myGrid2.DataSource = Service.GetProductsByCategories(categoryId);
                myGrid2.DataBind();
                break;

就这些

 private void Doldur2()
    {
        int catid = (int)Session["CategoryID"];
        WebHelper.FillGridView(myGrid2, Service.GetProductsByCategories(catid));
    }