Visual Studio .NET - Read from SQL server Views

Asked By Chris a on 09-Feb-06 05:59 PM
Hi,
I bind two dropdownlist to view table in SQL server database, the dropdownlist display just fine the only problem is it only selects index 0 and both dropdownlist.
No matter what I select, it only see the first selectedindex, I dunno if the view can be used for this purpose.
Dim myCmd As SqlCommand = New SqlCommand("SELECT DISTINCT storename, storeID FROM dbo.[TimeClock by Cashier]", myConn)
I wanted to read from view table because I query to filter out everything I didnt need already.
Thanks 
Chris

are you - Asked By mark macumber on 09-Feb-06 06:23 PM

Are you binding the data to the dropdown lists ONLY when the page is not posting back?
If you are not, then you need to add in the following code to your page_load method:
if (!Page.IsPostBack)
{
  //here you bind your dropdown lists
  dropdownlist.DataSource = mySource;
  dropdownlist.DataBind();
  dropdownlist.SelectedValue = 2;
  //this will select by value
  dropdownlist.SelctedIndex = 2;
  //this will select by index
}
this above code will only run when the user is NOT posting back to the page

Works - Asked By Chris a on 09-Feb-06 07:18 PM

Hi Mark,
That worked.
Thanks
Chris