如何遍历另一个gridview内的Gridview行 [英] How to Loop through Gridview rows which is inside another gridview

查看:81
本文介绍了如何遍历另一个gridview内的Gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,任何人都可以帮助我如何遍历gridview行,这是另一个gridview,我的任务是循环遍历内部网格的每一行,需要在内部网格内的文本框中更新记录是我的代码



Hi Everyone can any one help me out how to loop through gridview rows which is another gridview here my task is to loop through each row of inner grid and need to update the records with the value in the textbox inside the inner grid here is my code

protected void btnupdateregistry_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable dt = new DataTable();
            dt = WCFService.Host_Getstillneedsquantity(Session["hunqid"].ToString());
             //First grid
            foreach (DataListItem item12 in dMainCategory.Items)
            {
                DataList repHotDeals = (DataList)item12.FindControl("repHotDeals");

                //DataList repHotDeals = sender as DataList;
                foreach (DataListItem item in repHotDeals.Items)
                {
                    ModelId = Convert.ToInt32(((HiddenField)item.FindControl("hfddlmodelid")).Value);
                    int prevQty = 0;
                    int prevStillneedsQty = 0; //nag written..
                   
                    DataRow[] dr = dt.Select("id=" + ModelId);
                    prevQty = Convert.ToInt32(dr[0]["Quantity"].ToString());
                    prevStillneedsQty = Convert.ToInt32(dr[0]["stillneedsQuantity"].ToString()); 

                    TextBox quantityrequired = ((TextBox)item.FindControl("txtquantity"));
                    ViewState["txtquant"] = quantityrequired.Text;

                    Label SellingPrice = (Label)item.FindControl("lblsellingprice");
                    Label lblamount = (Label)item.FindControl("lblamount");

                    if (quantityrequired.Text != "" && int.Parse(quantityrequired.Text) >= prevQty)
                    {                  
                        int PurchasedQty = prevQty - prevStillneedsQty;                                             
                        int diffQnty = Convert.ToInt32(quantityrequired.Text) - prevQty;
                        int NewStillNeedsQnty = diffQnty + prevStillneedsQty;
                        WCFService.UpdateQuantity1(ModelId, Session["hunqid"].ToString(), Convert.ToInt32(quantityrequired.Text), NewStillNeedsQnty);

                    }
                    else
                    {
                        lblordsum.Visible = true;
                        lblordsum.Text = "Quantity Should Not Less than Purchased Quantity or Zero";
                        lblordsum.ForeColor = System.Drawing.Color.Red;
                    }
                    
                }
                
            }
            GetHostId("None");
            lblordsum.Text = "Requested Quantity is updated";
            lblordsum.Visible = true;
            lblordsum.ForeColor = System.Drawing.Color.Green;
        }
        catch (Exception ex)
        {
            WCFService.User_LogError("HostCollections", "lbtnAddtoCart_Click", (ex.InnerException != null) ? ex.InnerException.ToString() : ex.Message.ToString(), 4, 4);
        }
    }

推荐答案

要循环内部网格,可以使用以下代码(单击时)在按钮上)





gvMainGrid是父网格

gvInnerGrid是子网格



使用以下代码,您可以遍历任何控件。



For looping through the inner grid, you can use the below code (when clicking on a button)


gvMainGrid is the parent grid
gvInnerGrid is the child grid

Using the below code you can loop through any controls.

protected void btnUpdate_Click(object sender, EventArgs e)
       {
           for (int i = 0; i < gvMainGrid.Rows.Count; i++)
           {
               for (int j = 0; j < ((GridView)gv.Rows[i].FindControl("gvInnerGrid")).Rows.Count; j++)
               {
                   ((TextBox)((GridView)gvMainGrid.Rows[i].FindControl("gvInnerGrid")).Rows[j].FindControl("txtSNo")).Text = "100";

               }
           }
       }







希望这对你有帮助。




Hope this will help you.


这篇关于如何遍历另一个gridview内的Gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆