DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    126

    trouble with CheckBoxBoxList outside a DataList!!

    I have this checkboxlist out side a Datalist below:-

    <asp:checkboxlist id="chkList" AutoPostBack="True" Runat="server"
    DataValueField="ProductFeatureID"
    DataTextField="Feature"
    OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist></

    And the event that fires after when the checkBoxList is clicked
    -------------------------------------------------------
    Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles
    chkList.SelectedIndexChanged
    'print.Text = "Selected Item(s):<br><br>"
    Dim i As Integer
    For i = 0 To chkList.Items.Count - 1
    If chkList.Items(i).Selected Then
    P &= "_" & chkList.Items(i).Value
    'Tested it here to print it to the screen
    print.Text = P & "<br>"
    End If
    Next

    End Sub


    This is my link below in the DataList( What i want to get is the value
    selected below which is ok but after selecting a checkbox i want to
    append only the checbox value the user has selected but i noticed that
    after the Check_Clicked fires i can't get the right values appended to
    the link.
    What i really want is to get the CheckBoxLixt values appended to the link below after POSTBACK which i have set in the ChecKboxList control.But it seems the Datalist doesn't get the values after postback

    Any help please?

    ------------------------------------------------
    <a href='addtocart.aspx?productid=<%#
    DataBinder.Eval(Container.DataItem, "ProductID") & "&Features=" & P &
    ","
    %>'>Add To cart</a>

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this: Create a Public or Protected function named, say, SelectedFeatures:
    Code:
    Protected Function SelectedFeatures() As String
        Dim P As String
        For I As Integer = 0 To chkList.Items.Count - 1 
            If chkList.Items(i).Selected Then 
                P &= "_" & chkList.Items(i).Value 
            End If 
        Next
        Return P
    End Function
    Then change the code in your DataList to this:

    <a href='addtocart.aspx?productid=<%# DataBinder.Eval(Container.DataItem, "ProductID") & "&Features=" & SelectedFeatures() & "," %>'>Add To cart</a>
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2004
    Posts
    126
    Thx Phil for the reply. But after trying ur suggestion it still doesn't FIRE.
    The thing is that after a checkbox is clicked this method fires :-

    Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles
    chkList.SelectedIndexChanged
    'print.Text = "Selected Item(s):<br><br>"
    Dim i As Integer
    For i = 0 To chkList.Items.Count - 1
    If chkList.Items(i).Selected Then
    P &= "_" & chkList.Items(i).Value
    'Tested it here to print it to the screen
    print.Text = P & "<br>"
    End If
    Next
    End Sub

    And what i think is that since the CheckBoxlist is outside the DataList i can't seem to retrieve the variable after postback to append it to the QueryString.
    What i did is was added the function you recommended and changed the link accordingly but didn't fire..
    Is there still something 'm missing?
    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links