(asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="ResultField" DataValueField="DocLocation" Height="207px" Width="433px" AutoPostBack="True") (/asp:ListBox) (asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="(%$ ConnectionStrings:DMSConnectionString2 %)" SelectCommand="select *, Patient_Last as ResultField from master" ProviderName="(%$ ConnectionStrings:DMSConnectionString2.ProviderName %)") (/asp:SqlDataSource)VB.NET Code
' without this we get an error for a wrong value on SelectedIndex Me.ListBox1.SelectedIndex = -1 'Me.ListBox1.ClearSelection() Me.ListBox1.Items.Clear() ' submit the new query Me.SqlDataSource1.SelectCommand = c_SelectStr If Me.ListBox1.Items.Count > 0 Then Me.ListBox1.SelectedIndex = 0 Me.ListBox1_SelectedIndexChanged(Me.ListBox1, Nothing) Else ' clear the list 'Me.ListBox1.SelectedIndex = -1 'Me.ListBox1.ClearSelection() 'Me.ListBox1.Items.Clear() Me.ListBox1_SelectedIndexChanged(Me.ListBox1, Nothing) End IfWhen I check Me.ListBox1.Items.Count it always returns 0. I am thinking because the server code (vb.net) has not completed yet and the client has not been updated.