R
rn5a
I am binding a DropDownList with records existing in a database table.
I want to add an extra item *SELECT COMPANY* at index 0 so that by
default, it gets selected. This is how I tried it but the extra item
just doesn't get added to the DropDownList:
=============================================
<script runat="server">
Sub Page_Load(..........)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("....")
sqlDapter = New SqlDataAdapter("SELECT CompName FROM Company",
sqlConn)
ddlCompany.Items.Insert(0, "SELECT COMPANY")
dSet = New DataSet()
sqlDapter.Fill(dSet, "Company")
ddlCompany.DataSource = dSet.Tables("Company").DefaultView
ddlCompany.DataBind()
End Sub
</script>
<form runat="server">
<aspropDownList ID="ddlCompany" DataTextField="CompName"
runat="server"/>
</form>
=============================================
What am I doing wrong here?
I want to add an extra item *SELECT COMPANY* at index 0 so that by
default, it gets selected. This is how I tried it but the extra item
just doesn't get added to the DropDownList:
=============================================
<script runat="server">
Sub Page_Load(..........)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("....")
sqlDapter = New SqlDataAdapter("SELECT CompName FROM Company",
sqlConn)
ddlCompany.Items.Insert(0, "SELECT COMPANY")
dSet = New DataSet()
sqlDapter.Fill(dSet, "Company")
ddlCompany.DataSource = dSet.Tables("Company").DefaultView
ddlCompany.DataBind()
End Sub
</script>
<form runat="server">
<aspropDownList ID="ddlCompany" DataTextField="CompName"
runat="server"/>
</form>
=============================================
What am I doing wrong here?