更新时间:2022-12-08 19:50:58
尝试:foreach (GridViewItem g1 in dg_AgentSFR.Items)
{
忘记将GridViewRow更改为GridViewItem - OriginalGriff [/ edit]
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.
Try:foreach (GridViewItem g1 in dg_AgentSFR.Items) {
[edit]Forgot to change the GridViewRow to GridViewItem - OriginalGriff[/edit]