2

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!!

1
  • When you say page, do you mean Web Page, WPF Page, or Win Form? Commented Jun 14, 2010 at 6:12

3 Answers 3

2

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

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...

Sign up to request clarification or add additional context in comments.

3 Comments

hi peter, KroaX code suggestion works for me. However i still need to use the combinedValuesList in another page. How can i achieve this?
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"
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
0

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>;

Comments

0
//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 ?

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.