2013-03-13 37 views
0

我在一个页面上有两个gridview ..我列出第一个比从commandargument(“id”)我列出的第二个..但我正在做这些gridviews我可以完成第一个gridview,因为它没有必要赶上id来列出它。它列出了它所有的。但第二个,我想列出该产品的类别。你可以帮我吗 ?和单词的翻译;从gridview捕捉id到fillgridview

Doldur:填充/ Guncelle:更新/ SIL:删除/ vazgec:取消

错误的地方是全问号。感谢您的帮助

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

回答

1

您应该保存第二个网格的类别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)); 
    } 

多数民众赞成。