How do i move mutiple checked row value in a gridview in a single Session to another page.
that is say
session id = checkedbox1id, checkedbox5id, checkedbox7id.
session ppid = checkedbox1ppid, checkedbox5ppid, checkedbox7ppid.
I want to insert these mutiple checked row values in sessions into a databse in another page.
My code.
public partial class Default101 : System.Web.UI.Page
{
protected void ImageButton3_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvDetails.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
string id1 = row.Cells[1].Text;
string id2 = row.Cells[2].Text;
string id3 = row.Cells[5].Text;
string id5 = row.Cells[6].Text;
string id6 = row.Cells[8].Text;
Session["id1"] = id1;
Session["id2"] = id2;
Session["id3"] = id3;
Session["id5"] = id5;
Session["id6"] = id6;
//Finiding checkbox control in gridview for particular row
CheckBox chkdelete = (CheckBox)row.FindControl("chkSelect");
//Condition to check checkbox selected or not
if (chkdelete.Checked)
{
Response.Write(id1);
//string clicked = "";
}
}
}
BindUserDetails();
Response.Redirect("rrrr.aspx");
}
}
If i block the response redirect and response.write in the default101.aspx it dispalys correctly the session with mutiple value, but when i redirect it displays only the first record details in the grid view on the rrrr.aspx page and also insert only the first record in the gridview into the database.
Please help fix it
protected void Page_Load(object sender, EventArgs e)
{
string insertSQL22 = "INSERT INTO stocktracking (";
insertSQL22 += "stockid,packinglist,datesent,datereceived,location,status)";
insertSQL22 += "VALUES('";
insertSQL22 += Session["id1"].ToString() + "','";
insertSQL22 += Session["id2"].ToString() + "','";
insertSQL22 += Session["id3"].ToString() + "','";
insertSQL22 += Session["id5"].ToString() + "','";
insertSQL22 += Session["id6"].ToString() + "','";
insertSQL22 += 1 + "')";
String connectionString22 = "Data Source=NERE\\SQLEXPRESS01; Initial Catalog= kaging;Integrated Security=True";
SqlConnection con22 = new SqlConnection(connectionString22);
SqlCommand cmd22 = new SqlCommand(insertSQL22, con22);
int added22 = 0;
try
{
con22.Open();
//esponse.Write(insertSQL22);
added22 = cmd22.ExecuteNonQuery();
// Label1.Text = added.ToString();
if (added22 == 1)
{
}
else
{
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
con22.Close();
}
}