Button.cmdRefresh 为gridview 的子控件按钮,
我要在这个按钮的点击事件里面获取 gridview 中的 textbox 和 checkbox 。protected void cmdRefresh_Click(object sender, EventArgs e)   //"更新購物籃"
        {
            DataTable DT = (DataTable)Session["product_shopping_cart"];
            TextBox T = new TextBox();
            CheckBox C = new CheckBox();
            foreach (DataRow DW in DT.Rows)
            {
                for (int i = 0; i < DT.Rows.Count; i++)
                {
                    T = this.grvCart.Rows[i].FindControl("lblSubtotal") as TextBox;
                    if (T.Text != null)
                    {这个 T 控件为什么没获取到???

解决方案 »

  1.   

    for (int i = 0; i < DT.Rows.Count; i++) 
                    { 
                        if(DT.Rows[i].RowType == DataControlRowType.DataRow)
                        {

                            T = this.grvCart.Rows[i].FindControl("lblSubtotal") as TextBox; 
                            if (T.Text != null) 
                            { 
      

  2.   

    提示 DataRow 不存在 RowType  的定义 ......
      

  3.   

    foreach (GridViewRow gr in gridview.Rows) 
                { 
                       T = gr.FindControl("lblSubtotal") as TextBox; 
                 }
      

  4.   

    看错了,DT是DataTable,有个地方我不太明白,为什么你要遍历GrieView的行和DataTable的行呢?
      

  5.   

    protected void cmdRefresh_Click(object sender, EventArgs e)  //"更新購物籃" 

        int Index = ((GridViewRow)((Button)sender).NamingContainer).ItemIndex; 
        TextBox T = this.grvCart.Rows[Index].FindControl("lblSubtotal") as TextBox;
      

  6.   

    int Index = ((GridViewRow)((Button)sender).NamingContainer).ItemIndex; 改为: int Index = ((GridViewRow)((Button)sender).NamingContainer).RowIndex