Domanda

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"];
    }
}
È stato utile?

Soluzione

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"];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top