The first value of a dropdownlist


C

cesark

How can I show a value at the beginning of the dropdownlist with my
structure? This initial value isn' t in the database, for instance
'(Select)'.



<script language="VB" runat="server">

Sub Page_Load()

Dim strConnection As New
SqlConnection("Server=nou;database=market1;uid=sa;password=;")

Dim families As string = "SELECT family_Name FROM
Families;"



Dim DS1 As DataSet
Dim CommandFamilies As SqlDataAdapter

CommandFamilies = New SqlDataAdapter(families, strConnection)

DS1 = new DataSet()
CommandFamilies.Fill(DS1, "Families")


MySelect1.DataSource=
DS1.Tables("Families").DefaultView
MySelect1.DataBind()



End Sub

</script>



....

<form runat="server">

<asp:dropdownlist id="MySelect1"
DataTextField="family_Name" runat="server"
class="letter1">

</asp:dropdownlist>

....
 
Ad

Advertisements

G

George Durzi

not sure of the VB .net syntax, but here it is in C#

ListItem li = new ListItem();
YourDDL.Items.Add(li, 0);

put's a blank item at the beginning of your drop down list

cesark said:
How can I show a value at the beginning of the dropdownlist with my
structure? This initial value isn' t in the database, for instance
'(Select)'.



<script language="VB" runat="server">

Sub Page_Load()

Dim strConnection As New
SqlConnection("Server=nou;database=market1;uid=sa;password=;")

Dim families As string = "SELECT family_Name FROM
Families;"



Dim DS1 As DataSet
Dim CommandFamilies As SqlDataAdapter

CommandFamilies = New SqlDataAdapter(families, strConnection)

DS1 = new DataSet()
CommandFamilies.Fill(DS1, "Families")


MySelect1.DataSource=
DS1.Tables("Families").DefaultView
MySelect1.DataBind()



End Sub

</script>



...

<form runat="server">

<asp:dropdownlist id="MySelect1"
DataTextField="family_Name" runat="server"
class="letter1">

</asp:dropdownlist>

...




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
Ad

Advertisements

C

cesark

I have already achieved it 8) . The right code was:

MySelect2.Items.Insert(0, "(Select a value)")
MySelect2.SelectedIndex = 0

Just before of 'MySelect2.DataBind()'

Thank you anyway :)
 

Top