YES it really bothers us. That's why there are those nifty convienent code block tags for you to use. And responses like this to long-term members will get you noticed, and no one will be willing to help you in the future. Even if it does have a smiley face at the end.
What is the problem you are facing in saving the multiple rows.You have several ways to do it.
either you save it one by one ie call db one by one for all rows those are selected.
or another way you can,create the input in xml form and send to db and there parse the xml and save it in the table.
I have created a custom user control using Visual Studio 2008. The user enters data in three TextBoxes. The data is added in a DataTable which is bound to a ListBox. The user has the option of deleting items from the ListBox.
I also have two buttons which allow me to add user input from TextBox controls to the ListBox and delete items.
My question is:
When I select an item and try to delete it, the SelecteIndex becomes 0 during the postback and the first item is removed (not the one I select). Basically, the SelectedIndex does not persist during a postback. I have looked at different postings here and other sites as well, searched MSDN but I cannot figure out the answer. Is there a way to overcome this problem and how?
Probably because you're messing with the listitem collection within the dropdown, you do that, it'll get confused because as far as it's concerned, it's a new datasource and therefore there's no selected. How are you marking which one is deleted in your codebehind?
I'd probably create a seperate object to hold the data, use that as datasource for your dropdown and rebind each time otherwise there'll be a greater chance for state issues.
Thank you! That's interesting. Could you please elaborate a little bit?
I rebind the datasource every time the page is loaded. Are you saying that this is considered as messing with the listitem collection?
The code I use to delete the item is very simple (obviously I am trying to mark the item but I cannot):
int iIndex = lstNames.SelectedIndex;
if (iIndex > -1)
Every time I change the selection, I would like to retrieve the selected index. I cannot because during postback it is set to 0. I have tried to save the view state, but that did not work either. My problem is that I cannot get the selected index at any time at all. If at any point I could retrieve its value, I can store it somewhere. The problem is that I am reading 0 at all times. I don't know what to do.
I lose the selectedIndex the moment I have some action that does a postback. I have tried to capture it in may places, during Page_Init, LoadViewState, SaveViewState, with the IsPostBack, and without it, etc. For the past two days, I have had no success.
...a little bit later...
I am starting to believe that it is a data binding issue. You were absolutely correct. When I remove the databinding code, everything works fine. I need to figure out why.
Time is the fire in which we burn.
modified on Thursday, April 8, 2010 2:42 PM
Last Visit: 31-Dec-99 18:00 Last Update: 1-Aug-21 15:41