如何解决gridview的模板字段收款人姓名的错误 [英] how solve this error of template field Payeename of gridview

查看:77
本文介绍了如何解决gridview的模板字段收款人姓名的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void UpdateReport()
    {


        SqlCommand cmd;
        SqlDataReader rd;
        string sql = "";
        string CNo, Consigner, Consignee, Dt, BiltyFrm, BiltyTo, InvoiceNo = "";
        string NoOfPackages, ChargedWt, RatePerKg, Total_frieght, PaidBy, PayDetails;
        string Status = "", PaidAmt = "", PendingAmt = "", PayeeName = "";
       
        
        try
        {

            string constr = ConfigurationManager.ConnectionStrings["YET_DatabaseConnectionString"].ConnectionString.ToString();
            SqlConnection con = new SqlConnection(constr);
            con.Open();

            /*//objBll.BltInvoiceNo = txtInv.Text.ToString(); BillNo, RptDt, RefNo, RptTo, Branch
            objBll.RptRptDt = Convert.ToString(DateTime.ParseExact(txtDtRpt.Text, "MM/dd/yyyy", null));
            objBll.RptRefNo = txtRefNo.Text.ToString();
            objBll.RptRptTo = DDRptTo.Text.ToString();
            objBll.RptBranch = txtBranch.Text.ToString();
     
            objBll.Save("Report", "spInsertReport");

                //Response.Write("<script>alert('Data Save Successfully')</script>");
            

                clearReportInputText();*/

            //first delete all entris related to that Bill No....
           

            string str = "";
            //loop through all grid rows 1 by 1....
            for (int i = 0; i < GridView2.Rows.Count; i++)
            {
                CNo = GridView2.Rows[i].Cells[0].Text;
              
                PaidAmt = GridView2.Rows[i].Cells[13].Text;
                PendingAmt = GridView2.Rows[i].Cells[14].Text;
                //PayeeName = GridView2.Rows[i].Cells[18].Text;
               string strPayeeName = ((TextBox)GridView2.Rows[e.RowIndex].FindControl("txtPayeeName")).Text;
              
             

                Status = GridView2.Rows[i].Cells[20].Text;

                
                

                sql = "UPDATE Report SET " +
                    "PaidAmt=" + PaidAmt + "," +
                    "PendingAmt=" + PendingAmt + "," +
                    //"PayeeName='" + PayeeName + "'," +
                    "status='" + Status + "'" +
                    //"BillStatus='" + txtbillstatus.Text + "'" + 
                    "WHERE CNo='" + CNo + "' and BillNo=" + txtBillNo.Text;



                cmd = new SqlCommand(sql, con);
                cmd.ExecuteNonQuery();


            }

            
            con.Close();
            showError("Updated successfully");
            //MessageBox.Show("saved");

            loadDataInTree();
        }
        catch (Exception ex)
        {
            // MessageBox.Show("Err in private  void SaveReport() :" + ex.Message);
            showError(ex.Message);
        }
    }

推荐答案

您的问题是e.RowIndex.

您的方法不使用EventArgs.

您使用
your problem is e.RowIndex.

Your method does not use EventArgs.

you use
for (int i = 0; i < GridView2.Rows.Count; i++)


遍历GridViewRows.

您可以进行一次foreach迭代:


to go through the GridViewRows.

you could make a foreach iteration:

foreach (GridViewRow row in GridView2.Rows)


比您可以使用row.Cells.FindControl方法


Than you can use row.Cells.FindControl method


这篇关于如何解决gridview的模板字段收款人姓名的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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