I have this code
protected void btnPrasaj_Click(object sender, EventArgs e)
{
List<ListItem> lista = new List<ListItem>();
string prasanje = null;
Application.Lock();
if (Application["prasanja"] == null) // za prvpat se postavuva prasanje
{
prasanje = txtNaslov.Text + "\n\n\n" + txtPrasanje.Text;
lista.Add(new ListItem(prasanje, ddltema.SelectedIndex.ToString()));
lstProblemPrasanje.DataSource = lista;
lstProblemPrasanje.DataTextField = "Text";
lstProblemPrasanje.DataValueField = "Value";
lstProblemPrasanje.DataBind();
Application["prasanja"] = lista;
}
else
{
lista=(List<ListItem>)Application["prasanja"];
prasanje = txtNaslov.Text + "\n\n\n" + txtPrasanje.Text;
lista.Add(new ListItem(prasanje, ddltema.SelectedIndex.ToString()));
lstProblemPrasanje.DataSource = lista;
lstProblemPrasanje.DataTextField = "Text";
lstProblemPrasanje.DataValueField = "Value";
lstProblemPrasanje.DataBind();
Application["prasanja"] = lista;
}
Application.UnLock();
}
And when I click this button in the ListBox I get numbers (which is the value of the item) instead the content of the text field.
Since your datasource is List of ListItems, you don’t have to specify DataTextField and DataValueField. Just comment out the following lines.
So your code should be: