loop for store Id in a list
-
I wrote this code for getting the id of every row in gridview when a button click.I don't know what code should i write for loop(because maybe a user click on several button to order a product).I want to when a button click the Id of it store in a list.
protected void grid_product(object sender, GridViewCommandEventArgs e)
{
string currentcommand = e.CommandName;
int currentrowindex = Int32.Parse(e.CommandArgument);
string productid = GridView1.DataKeys[currentrowindex].Value;
} -
I wrote this code for getting the id of every row in gridview when a button click.I don't know what code should i write for loop(because maybe a user click on several button to order a product).I want to when a button click the Id of it store in a list.
protected void grid_product(object sender, GridViewCommandEventArgs e)
{
string currentcommand = e.CommandName;
int currentrowindex = Int32.Parse(e.CommandArgument);
string productid = GridView1.DataKeys[currentrowindex].Value;
}You could store the data in an arraylist and store that arraylist in the ViewState similar to:
public ArrayList GetProductList
{
if(ViewState["ProductList"]==null)
{
ViewState["ProductList"] = new ArrayList();
}
return (ArrayList)ViewState["ProductList"];
}public void AddProduct(int productId)
{
if(ViewState["ProductList"]==null)
{
ViewState["ProductList"] = new ArrayList();
}((ArrayList)ViewState["ProductList"]).Add(productId);
}Then when you want to add something to your product list you can call it using
AddProduct(productId);
And you can cycle through your ArrayList:
foreach(int productId in GetProductList().Items)
{
//execute code for productId
}I'm not at my workstation at the moment, but this should help you get started on your problem. Best of luck!!! :)
Cheers Disgyza Programmer Analyst
-
You could store the data in an arraylist and store that arraylist in the ViewState similar to:
public ArrayList GetProductList
{
if(ViewState["ProductList"]==null)
{
ViewState["ProductList"] = new ArrayList();
}
return (ArrayList)ViewState["ProductList"];
}public void AddProduct(int productId)
{
if(ViewState["ProductList"]==null)
{
ViewState["ProductList"] = new ArrayList();
}((ArrayList)ViewState["ProductList"]).Add(productId);
}Then when you want to add something to your product list you can call it using
AddProduct(productId);
And you can cycle through your ArrayList:
foreach(int productId in GetProductList().Items)
{
//execute code for productId
}I'm not at my workstation at the moment, but this should help you get started on your problem. Best of luck!!! :)
Cheers Disgyza Programmer Analyst
I want to store Id in a list and list in a session.in another page I want to use these id in a gridview.my code is for shopping cart.
-
I want to store Id in a list and list in a session.in another page I want to use these id in a gridview.my code is for shopping cart.
And? Just extract the list again as shown in the demo code .. If you want to store it in the session then change view state for session!? Not rocket science.
I'm largely language agnostic
After a while they all bug me :doh: