RSS Forums RSS

listbox and selectedvalue urgent

Reply
Posts: 256
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 0
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

listbox and selectedvalue urgent

  #1  
Dec 1st, 2008
hi,

I am trying to add a value to listbox. i use lstlistbox.items.add(new listitem(value)).

this adds it fine in click event of button, but i need to use the selectedvalue of the listbox again in same event.

as the listbox item doesnt show i cant use selectedvalue. is there a way to first populate the listbox with its selected value then somehow use the value.

thanks
AddThis Social Bookmark Button
Reply With Quote  
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 9
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: listbox and selectedvalue urgent

  #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?

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then

            For iCnt As Integer = 1 To 5
                Dim lItem As New ListItem
                lItem.Text = String.Format("New Item {0}", iCnt.ToString)
                lItem.Value = iCnt
                Me.ListBox1.Items.Add(lItem)
                lItem = Nothing
            Next iCnt
        End If
    End Sub

    Protected Sub ListBox1_SelectedIndexChanged( _
            ByVal sender As Object, _
            ByVal e As System.EventArgs) _
            Handles ListBox1.SelectedIndexChanged
        HttpContext.Current.Response.Write( _
             String.Format("Selected Value = {0}", _
             CType(sender, ListBox).SelectedValue.ToString))
    End Sub
End Class

pagecode;
<%@ Page 
    Language="VB" 
    AutoEventWireup="false" 
    CodeFile="Default.aspx.vb" 
    Inherits="_Default" %>
<!DOCTYPE 
    html PUBLIC 
    "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form 
        id="form1" 
        runat="server">
    <div>
        <asp:ListBox 
            ID="ListBox1" 
            runat="server" 
            AutoPostBack="True" />
    </div>
    </form>
</body>
</html>
Last edited by 4advanced : Dec 1st, 2008 at 6:48 am.
Reply With Quote  
Posts: 43
Reputation: reach_yousuf is an unknown quantity at this point 
Solved Threads: 5
reach_yousuf reach_yousuf is offline Offline
Light Poster

Re: listbox and selectedvalue urgent

  #3  
Dec 2nd, 2008
hii

Add the code code in your .aspx

<asp:DropDownList id="ddl1"  runat="server" AutoPostBack="True" AppendDataBoundItems="True"   >   
        <asp:ListItem Selected="True" Value="-1">--Select Me--</asp:ListItem>
        <asp:ListItem Value="1">Value 1</asp:ListItem>
        <asp:ListItem Value="2">Value 2</asp:ListItem>
        
     </asp:DropDownList>

And you can bind additional values at run time from database and can use selected

Private Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1.SelectedIndexChanged
       
your code 
    End Sub

Mark as solved if it helps you!!!

Regards
Yousuf
Software Developer
Reply With Quote  
Posts: 8
Reputation: paslanmaz is an unknown quantity at this point 
Solved Threads: 0
paslanmaz paslanmaz is offline Offline
Newbie Poster

Re: listbox and selectedvalue urgent

  #4  
Dec 3rd, 2008
can u specify problem
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the ASP.NET Forum
Views: 819 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:03 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC