Question

I have two gridview on one page.. i have listed the first one than from commandargument("id") i listed the second one.. but i am doing something on these gridviews i can fulfill the first gridview because it is not necessary to catch id to list it. it is listing all it has. but the second one, i want to list just the categoryid of that product. can you help me ? and the translation of the words;

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

The wrong place is with full of question mark. Thanks for your help

     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();
    }
}
Was it helpful?

Solution

you should save category id for second grid.

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

and

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

thats all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top