Hello,
I am writing a page (C#) that uses one ListBox that retrieves data from a DB using SqlDataSource and the SelectCommand.
The Listbox populates fine and also retrieves values fine. I put a button under it that, when pressed, uses the Text of the selected item in this ListBox to query the DB using another SelectCommand of a separate SqlDataSource to retrieve other data and place it in a second ListBox so it is dynamically updated while maintaining the original items in the original ListBox.
My problem is when I select an item in the second ListBox and attempt to retrieve the data, it always brings the selection to the first one in the list, and making the data I am trying to retrieve set to the first item. Upon doing some searching and debugging, I found that the problem seems to be in updating the SqlDataSource.S electCommand. It seems that when I update it, it repopulates the ListBox correctly but doing anything that causes any type of page loading or interaction causes the selection to either go to index 0 (after ListBox2 repopulates) or jump around (before it gets repopulated).
Any help, advice, or workarounds would be greatly appreciated.
I am writing a page (C#) that uses one ListBox that retrieves data from a DB using SqlDataSource and the SelectCommand.
Code:
<asp:SqlDataSource ID="DataSource1" SelectCommandType=Text runat="server" ConnectionString="<%$ ConnectionStrings:SQLDB %>" /> <asp:ListBox ID="ListBox1" runat="server" SelectionMode=Single Rows=20 Width="250px" DataSourceID="DataSource1" >
My problem is when I select an item in the second ListBox and attempt to retrieve the data, it always brings the selection to the first one in the list, and making the data I am trying to retrieve set to the first item. Upon doing some searching and debugging, I found that the problem seems to be in updating the SqlDataSource.S electCommand. It seems that when I update it, it repopulates the ListBox correctly but doing anything that causes any type of page loading or interaction causes the selection to either go to index 0 (after ListBox2 repopulates) or jump around (before it gets repopulated).
Any help, advice, or workarounds would be greatly appreciated.
Comment