Thursday, March 22, 2012

The first value of a dropdownlist

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 =--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" <cesar_casafont@.hotmail-dot-com.no-spam.invalid> wrote in message
news:400db905$1_2@.127.0.0.1...
> 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
=--
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 :)

--== 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 =--

0 comments:

Post a Comment