gridview rows in asp.net

Posted by Dn2010 under ASP.NET on 4/5/2012 | Points: 10 | Views : 1357 | Status : [Member] | Replies : 2
hi friends,

i inserted records from gridview rows to database,

its working,

for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];

OpenConnection(con);

str = "insert into cdr (duration,userfield) values('" + row.Cells[0].Text + "','" + row.Cells[1].Text + "'')";

SqlCommand com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();

}

lblMessage.Text = "Records inserted";




but if i give paging in gridview ,

insert only first page records,

please give the code for it.


thanks.




Responses

Posted by: Kavi.Sirius on: 4/11/2012 [Member] Starter | Points: 25

Up
0
Down
hi,

i cant to get ur question,
explain clearly.

Regards
kavi.n

Regards
Kavi.n

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
You can do onething. You can use dataset instead of gridview to insert records in database.

Example:

DataSet ds=new DataSet();

ds=GridView1.DataSource;

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{

OpenConnection(con);

str = "insert into cdr (duration,userfield) values('" + ds.Tables[0].Row[i][0].ToString() + "','" + ds.Tables[0].Row[i][1].ToString() + "'')";

SqlCommand com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();

}
lblMessage.Text = "Records inserted";



Try it.






Thanks,
Rajni Shekhar

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response