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
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- If Not Me.IsPostBack Then
- populateComboBox()
- StockTypeCodeList.SelectedIndex = 0
- End If
- MessageBox.Visible = False
- End Sub
- Private Sub populateComboBox()
- Try
- Dim IdDataSet As DataSet
- Dim Controller As TMMI
- Controller = New TMMI()
- IdDataSet = Controller.ShowID()
- Dim IdTable As DataTable
- IdTable = IdDataSet .Tables("ID")
- IdList.DataSource = IdTable
- IdList.DataTextField = "Description"
- IdList.DataValueField = "ID"
- IdList.DataBind()
- MessageBox.Visible = False
- Catch ex As SqlClient.SqlException
- MessageBox.Text = "Database error" + "<br />" + ex.Message
- MessageBox.Visible = True
- Catch ex As Exception
- MessageBox.Text = ex.Message
- MessageBox.Visible = True
- End Try
- End Sub
Jason