View Single Post
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: listbox and selectedvalue urgent

 
0
  #2
Dec 1st, 2008
I'm sorry but I don't understand your problem.
Lets assume you have the below stated example, it adds a few items to the listbox and after a selection is done, it responds the selected value to the page.....

Is thát what you achieved?

  1. Partial Class _Default
  2. Inherits System.Web.UI.Page
  3.  
  4. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5. If Not Page.IsPostBack Then
  6.  
  7. For iCnt As Integer = 1 To 5
  8. Dim lItem As New ListItem
  9. lItem.Text = String.Format("New Item {0}", iCnt.ToString)
  10. lItem.Value = iCnt
  11. Me.ListBox1.Items.Add(lItem)
  12. lItem = Nothing
  13. Next iCnt
  14. End If
  15. End Sub
  16.  
  17. Protected Sub ListBox1_SelectedIndexChanged( _
  18. ByVal sender As Object, _
  19. ByVal e As System.EventArgs) _
  20. Handles ListBox1.SelectedIndexChanged
  21. HttpContext.Current.Response.Write( _
  22. String.Format("Selected Value = {0}", _
  23. CType(sender, ListBox).SelectedValue.ToString))
  24. End Sub
  25. End Class

pagecode;
  1. <%@ Page
  2. Language="VB"
  3. AutoEventWireup="false"
  4. CodeFile="Default.aspx.vb"
  5. Inherits="_Default" %>
  6. <!DOCTYPE
  7. html PUBLIC
  8. "-//W3C//DTD XHTML 1.0 Transitional//EN"
  9. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11. <head runat="server">
  12. <title></title>
  13. </head>
  14. <body>
  15. <form
  16. id="form1"
  17. runat="server">
  18. <div>
  19. <asp:ListBox
  20. ID="ListBox1"
  21. runat="server"
  22. AutoPostBack="True" />
  23. </div>
  24. </form>
  25. </body>
  26. </html>
Last edited by 4advanced; Dec 1st, 2008 at 7:48 am.
Reply With Quote