I’m iterating through the GridView rows and cells to get the values and store them in a 2D array.
This is my code:
for (int i = 0; i < GridView2.Rows.Count; i++)
{
for (int j = 0; j < (GridView2.Rows[i].Cells.Count - 3); j++)
{
// using the labels of the template fields.....
Label values = (Label)GridView2.Rows[i].Cells[j].FindControl("Label" + j);
GridValues[i,j] = values.Text; // gridvalues is my 2d array.
}
}
What I need now is to make the same values I got from the above loop to be added to a list(2D). So I created a class of that list
This is the code:
public class GridValuesClass
{
public string GridCustomerName { get; set; }
public string GridPickUpPoint { get; set; }
public DateTime GridPickUpDate { get; set; }
public TimeSpan GridDropPoint { get; set; }
public DateTime GridDropDate { get; set; }
public string GridCabStatus { get; set; }
public string GridAssignedCab { get; set; }
public TimeSpan GridActualDropTime { get; set; }
}
These properties represent the column names in the gridview.
So, how can I add the values in the gridview inside this class?
And how can I retrieve the values if my values are present in the list<GridValuesClass>
You don’t need to store it in a 2D array to be later stored in a list. Instead you can store it directly in to the list.
Sort of like this:
Hope this helps.
As a side note, use more meaningful names.
GridValuesClass, if you have several grid views then this name becomes useless. From what I gather on how you named the properties, it looks more like a job order for cabs. So maybeJobOrder?GridView2tells us nothing. What kind of data does the gridview contain? PerhapsJobsGridView?Grid? What if the data is stored or used in a context where there is no grid view?