本文介绍了DataGrid不包含'Rows'的定义,也没有扩展方法'Rows'接受类型'System.Web.UI.WebControls.DataGrid'的第一个参数'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
当我尝试迭代gridview时会抛出上述错误。在$ pre> dg_AgentSFR.Rows
这是我的代码:
protected void savedatafromgv()
{
foreach(dg_AgentSFR.Rows中的GridViewRow g1)
{
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = con.CreateCommand();
cmd =新的SqlCommand(INSERT INTO TB_TransAgenSeaFreightRate(POL,POD,FORWARDER,FORWARDER REFERENCE,SHIPPING LINE,CONTAINER TYPE,CONTAINER SIZE,VALIDITY FROM,VALIDITY TO,BASIC RATE,PAF,CAF,PSS,TOTAL AMOUNT, REE DAYS,CREDIT DAYS,NIT DEPOSIT,COMPANYID,ISACTIVE)值('+ g1.Cells [0] .Text +','+ g1.Cells [1] .Text +','+ g1。 Cells [2] .Text +','+ g1.Cells [3] .Text +','+ g1.Cells [4] .Text +','+ g1.Cells [5]。 Text +','+ g1.Cells [6] .Text +','+ g1.Cells [7] .Text +','+ g1.Cells [8] .Text +', '+ g1.Cells [9] .Text +','+ g1.Cells [10] .Text +','+ g1.Cells [11] .Text +','+ g1。 Cells [12] .Text +','+ g1.Cells [13] .Text +','+ g1.Cells [14] .Text +','+ g1.Cells [15]。 Text +','+ g1.Cells [16] .Text +',1,'+ TXTCompanyID.Text +'),con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
Response.Write(记录插入成功);
}
任何1可以帮我解决这个问题。
提前致谢。
解决方案
Hi
When i try to iterate through the gridview it throws the above error.Getting error in For loop near
dg_AgentSFR.Rows
Here is my code:
protected void savedatafromgv() { foreach (GridViewRow g1 in dg_AgentSFR.Rows) { SqlConnection con = new SqlConnection(strConnString); SqlCommand cmd = con.CreateCommand(); cmd = new SqlCommand("INSERT INTO TB_TransAgenSeaFreightRate(POL,POD,FORWARDER,FORWARDER REFERENCE,SHIPPING LINE,CONTAINER TYPE,CONTAINER SIZE,VALIDITY FROM,VALIDITY TO,BASIC RATE,PAF,CAF,PSS,TOTAL AMOUNT,REE DAYS,CREDIT DAYS,NIT DEPOSIT,COMPANYID,ISACTIVE) values ('" + g1.Cells[0].Text + "','" + g1.Cells[1].Text + "','" + g1.Cells[2].Text + "','" + g1.Cells[3].Text + "','" + g1.Cells[4].Text + "','" + g1.Cells[5].Text + "','" + g1.Cells[6].Text + "','" + g1.Cells[7].Text + "','" + g1.Cells[8].Text + "','" + g1.Cells[9].Text + "','" + g1.Cells[10].Text + "','" + g1.Cells[11].Text + "','" + g1.Cells[12].Text + "','" + g1.Cells[13].Text + "','" + g1.Cells[14].Text + "','" + g1.Cells[15].Text + "','" + g1.Cells[16].Text + "',1,'" + TXTCompanyID.Text + "')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } Response.Write ("Records inserted successfully"); }
Can any 1 please help me to resolve this issue. Thanks in advance.
解决方案
这篇关于DataGrid不包含'Rows'的定义,也没有扩展方法'Rows'接受类型'System.Web.UI.WebControls.DataGrid'的第一个参数'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!