tags:

views:

67

answers:

3

hi guys,

i just want to ask help again. I've created a method to read values in gridview, i was able to get and read values from the gridview. The problem now, is how can i store the values inside an array and i want it to pass on the other page. here's the code i've created

    private void getrowvalues()
    {
        string combinedvalues;

        foreach (GridViewRow row in gvOrderProducts.Rows)
        {
            string prodname = ((Label)row.FindControl("lblProductName")).Text;
            string txtvalues = ((TextBox)row.FindControl("txtQuantity")).Text;

            combinedvalues = prodname + "|" + txtvalues;
        }
    }

i want the result string combinedvalues to be put in an array or collection of strings which i can be access in other page. Is there a way to do it? Any inputs will be greatly appreciated.

thanks!!

A: 
//Before Foreach

List<string> combinedvalueList = new List<string>();

//Inside Foreach
combinedvalueList.add(combinedvalues);

Please also see

List MSDN

There you can see samples and Methods of List class. It seems to me you are completely new to c# and programming in general ?

KroaX
hi KroaX,thanks for the quick reply. However, i still need to access the list and use it in another page. How can i achieve this?
nhoyti
+1  A: 

Just saw KroaX answer which is the same, I leave mine for the example code. Please accept KroaX answer, though...

private void getrowvalues()
{
    string combinedvalues;
    List<string> combinedValuesList = new List<string>();

    foreach (GridViewRow row in gvOrderProducts.Rows)
    {
        string prodname = ((Label)row.FindControl("lblProductName")).Text;
        string txtvalues = ((TextBox)row.FindControl("txtQuantity")).Text;

        combinedvalues = prodname + "|" + txtvalues;
        combinedValuesList.Add(combinedvalues);
    }
    // use combinedValuesList or combinedValuesList.ToArray()
}

Notepad code, untested...

Peter
hi peter, KroaX code suggestion works for me. However i still need to use the combinedValuesList in another page. How can i achieve this?
nhoyti
That's a new question and I think you should indicate ASP.NET (?) for that question, if I'm guessing you application type correctly... I'm not very good with ASP.NET programming, but think you could store the list in "Session State"
Peter
See Danny Chens example how to pass objects to another page. You could also achieve this on other ways but Danny's example is the most simple one I guess
KroaX
A: 

To pass something from one page to another, you can store it in the session (sometimes it depends).

Session["combinedvalueList"] = combinedvalueList;

While in another page, you can access it.

if (Session["combinedvalueList"]!=null)
      combinedValueList = Session["combinedvalueList"] as List<string>;
Danny Chen