I am writing a page (C#) that uses one ListBox that retrieves data from a DB using SqlDataSource and the SelectCommand.
Expand|Select|Wrap|Line Numbers
- <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.SelectCommand. 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.