I have grid in my page which have four columns with multiple rows
Userid username stateid and statename
which collection i should use to send data to another page using session
my code is
string[] strArray = new string[] {};
foreach (GridViewRow gr in gvCompany.Rows)
{
strArray =new string[4] {new[] {gr.Cells[0].Text}.ToString(), new[] {gr.Cells[1].Text}.ToString(), new[] {gr.Cells[2].Text}.ToString(),new[] {gr.Cells[3].Text}.ToString()};
}
Session["List"] = strArray;
Response.Redirect("Tid.aspx?Mode=List");
on tid page my code is
string[] ls = new string[] { };
ls =(string[]) Session["List"];
foreach (string st in ls )
{
//get each cell
}
but value of st is system.string rather than value
Using an string[] is not recommended since the more fields will add in future the difficult it will get to keep the field and index relationship bug free..
You can create a proper class object eg. Company and pass a List to other class, List is in System.Collections.Generic namespace.