Reputation: 297
I have a listbox in asp.net I tried when user click on it's item in runtime can change the text of this item without change the order of the the items . So I try to make Edit button when click on it get the item value as
protected void btnEditListValue_Click(object sender, EventArgs e)
{
string listvalue = lstParameters.Items.IndexOf(lstParameters.SelectedItem).ToString();
string listText = lstParameters.SelectedItem.ToString();
}
then I will make textbox fill value from string listText
to enable user to edit
what shall I do after that to keep listbox order as old without delete and insert again
please help
Upvotes: 0
Views: 1071
Reputation: 460138
You can overwrite the ListItem.Text
, f.e. when the user changed the text:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if(lstParameters.SelectedIndex >= 0 && !String.IsNullOrWhiteSpace(TextBox1.Text))
{
ListItem selectedItem = lstParameters.Items[lstParameters.SelectedIndex];
selectedItem.Text = TextBox1.Text;
}
}
Upvotes: 1