Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a list of products in gridview.In gridview there is check box for each row. Each row contains Car Name, Car Price.I am accessing carid value thru DataKeys property of gridview .What I want is

when user clicks on Book button I want to store each row values in something which I don't know how and use each row values to be displayed for particular user on another page.
I am thinking it analogous to shopping cart but I want only selected values and there is no such thing as quantity.
I want to do this using session.Somehow I want to store the list in session variable so that row values which are selected earlier can be used to update database.
Any help is appreciated.This is what I have done so far

C#
protected void btnbook_Click(object sender, EventArgs e)
{
   int id = 0;
   foreach (GridViewRow gvrow in gvcar.Rows)
   {
        if (((CheckBox)gvrow.FindControl("chkSelect")).Checked == true)
        {
           var dataKey = gvcar.DataKeys[gvrow.RowIndex];
           if (dataKey != null)
              Response.Write((string) ("ID:"+dataKey.Value+"Name of Car"+gvrow.Cells[1].Text));
        }
        else
        {
           MessageBox.Show("Please select a car");
        }
    }
}
Posted

1 solution

Create a list of the type like if you already have a class for car ,create
List<car> selectedList = new List<car>();
If you don't have it, create a class and add the selected row values to this list and bind this list to another gridview on another page
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900