As suggested you should use server side control
DropDownList. If you want to get value back when the user changes selection than you have to set AutoPostBack property to
true and asign SelectedIndexChanged Event. Please examine the example:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
For index = 1 To 10
DropDownList1.Items.Add(
New ListItem("Test " + index.ToString(), index.ToString())
)
Next
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Label1.Text =
String.Format("Selected Value '{0}'; Selected Text '{1}'",
DropDownList1.SelectedValue,
DropDownList1.SelectedItem.Text
)
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label2.Text =
String.Format("Selected Value '{0}'; Selected Text '{1}'",
DropDownList1.SelectedValue,
DropDownList1.SelectedItem.Text
)
End Sub
Please "Mark As Answer" if the post helped you.
mitja.gti | www.mitjagti.com
What do you want to add in that loop? with a dropdownlist control you can use databind and if you want to, it's really easy to make some items non selectable
Please remember to post your code.
If this post answered your question or solved your problem, please Mark it as Answer.
I want to add dropdownlist in loop fro ex dropdownlist1 and another one by loop dropdownlist2 dropdownlist3 dropdownlist4... like this And its work only with HTML dropdownlist
In case you insist with HTML Select element then you will have to use JavaScript.
Option A: You will have to share your server side propery with client side (Public Property). When ever the client changes selection you will have to get the new value and update the property. You can find an example
here.
Option B: Instead of shared property you can use
pageMethods.
Please "Mark As Answer" if the post helped you.
mitja.gti | www.mitjagti.com
Dear no need for JavaSecript!! for ex html inbut (text box html) just add (runat=server) then you can use it in vb code!!! so I tried to add this into Select (html dropdown) but not work how can I get this drop proporty in Vb code!!!
diyaa jamal
Member
195 Points
140 Posts
HTML Select (DropDownList)
Aug 18, 2012 07:35 PM|LINK
Hello All,
I have Select control (HTML) and I want to use this control in VB cod
<select id="Select1"> <option value="1"> Test 1 </option> <option value="2"> Test 2 </option> </select>For Ex.
msgbox(select.selectedvalue)
How can I do it?
MetalAsp.Net
All-Star
112241 Points
18268 Posts
Moderator
Re: HTML Select (DropDownList)
Aug 18, 2012 08:05 PM|LINK
diyaa jamal
Member
195 Points
140 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 09:13 PM|LINK
mitja.GTI
Star
11157 Points
2094 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:08 PM|LINK
As suggested you should use server side control DropDownList. If you want to get value back when the user changes selection than you have to set AutoPostBack property to true and asign SelectedIndexChanged Event. Please examine the example:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"></asp:DropDownList> <br /> <asp:Label ID="Label1" runat="server"></asp:Label> <br /> <asp:Button ID="Button1" runat="server" Text="Button" /> <br /> <asp:Label ID="Label2" runat="server"></asp:Label>Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then For index = 1 To 10 DropDownList1.Items.Add( New ListItem("Test " + index.ToString(), index.ToString()) ) Next End If End Sub Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged Label1.Text = String.Format("Selected Value '{0}'; Selected Text '{1}'", DropDownList1.SelectedValue, DropDownList1.SelectedItem.Text ) End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Label2.Text = String.Format("Selected Value '{0}'; Selected Text '{1}'", DropDownList1.SelectedValue, DropDownList1.SelectedItem.Text ) End Submitja.gti | www.mitjagti.com
diyaa jamal
Member
195 Points
140 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:12 PM|LINK
Trolderik
Member
645 Points
355 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:32 PM|LINK
What do you want to add in that loop? with a dropdownlist control you can use databind and if you want to, it's really easy to make some items non selectable
If this post answered your question or solved your problem, please Mark it as Answer.
diyaa jamal
Member
195 Points
140 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:35 PM|LINK
mitja.GTI
Star
11157 Points
2094 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:36 PM|LINK
I am afraid that I am NOT your dear.
In case you insist with HTML Select element then you will have to use JavaScript.
Option A: You will have to share your server side propery with client side (Public Property). When ever the client changes selection you will have to get the new value and update the property. You can find an example here.
Option B: Instead of shared property you can use pageMethods.
mitja.gti | www.mitjagti.com
Trolderik
Member
645 Points
355 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:42 PM|LINK
So, you want to enable one dropdownlist when something is selected in another?
If this post answered your question or solved your problem, please Mark it as Answer.
diyaa jamal
Member
195 Points
140 Posts
Re: HTML Select (DropDownList)
Aug 18, 2012 11:46 PM|LINK