Question

I wrote this code and it gives me only the last element of the column in a list. How can I get all elements in the TextBox?

SPListItemCollection items = list.GetItems(myquery);

foreach (SPListItem item in items)
{
    if (item["Title"] != null)
    {
        TextBox1.Text = (string)item["Title"];
    }
}
Était-ce utile?

La solution

You are overwriting the text within the text box at each iteration, so you only see the last value... Try this:

TextBox1.Text = TextBox1.Text + " " + (string)item["Title"];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top