By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

need help sorting a dropdownlist control on a webfom

P: 3

I am making a webform, and am trying to populate a dropdownlist with a dataset from a called stored procedure. This is where I run into two problems:

1: How do I get the dropdownlist to popluate, but display nothing when the page is loaded? I can get it to populate, but cannot figure out how to set it to nothing.

2: How do I sort the dropdownlist? It is populated by a dataset containing a datable with two columns.
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         If Not Me.IsPostBack Then
  3.             populateComboBox()
  4.             StockTypeCodeList.SelectedIndex = 0
  5.         End If
  6.         MessageBox.Visible = False
  7.     End Sub
  9. Private Sub populateComboBox()
  10.             Try
  11.             Dim IdDataSet As DataSet
  12.             Dim Controller As TMMI
  13.             Controller = New TMMI()
  14.             IdDataSet = Controller.ShowID()
  15.             Dim IdTable As DataTable
  16.             IdTable = IdDataSet .Tables("ID")
  17.             IdList.DataSource = IdTable
  18.             IdList.DataTextField = "Description"    
  19.             IdList.DataValueField = "ID" 
  20.             IdList.DataBind()
  21.             MessageBox.Visible = False
  22.         Catch ex As SqlClient.SqlException
  23.             MessageBox.Text = "Database error" + "<br />" + ex.Message
  24.             MessageBox.Visible = True
  25.         Catch ex As Exception
  26.             MessageBox.Text = ex.Message
  27.             MessageBox.Visible = True
  28.         End Try
  29.     End Sub
Any help is appreciated, so thanks in advance,
Apr 10 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.