Solved

userfulness indicator Asp.net using Vb Code

Posted on 2012-12-22
11
575 Views
Last Modified: 2012-12-23
I am trying to create a usefulness indicator on a page in asp.net using vb code behind. I have my reviews displaying in repeater control which has paging enabled. I have included two buttons to the end of the repeater one for Yes and the other No. I want to keep a count of how many times yes was clicked for that review and how many times no was clicked. By adding the yes count and no count together I can get the total. I can access the buttons but when I click them nothing happens. Would anyone be able to help? I've been trying to do this for hours and I can't find a solution. Below is the code I have used for both the paging and the attempt for the indicator.

Markup Code:
<asp:Repeater ID="movies" runat="server" onItemCommand="movies_ItemCommand">
        <ItemTemplate>
            <table width="641px">
                <tr>
                    <td>
                        <span style="font-weight:bold;font-size:16px;">
                        <%# Container.DataItem("MovieTitle")%>
                            </span>
                    </td>
                    <td>
                        <span style="float:right;">
                        <asp:Image ID="Image1" runat="server" ImageUrl = '<%# Eval("Total")%>' style="width:80px;height:14px;"/>
                       </span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <hr style="height:1px;border-bottom:none;color:#e3e3e3;"/>
                    </td>
                </tr>
                </table>
            <table width="641px">
                <tr>
                    <td>
                        <asp:Image ID="Image2" runat="server" ImageUrl = '<%# Eval("MovieImageFileName")%>' style="width:180px;height:108px;border:1px solid #e3e3e3;"/>
                    </td>
                    <td style="vertical-align:top;">
                        <%# Container.DataItem("ReviewText")%>
                    </td>
                </tr>
                </table>
            <table width="641px">
                
                <tr>
                    <td>
                      Value for Money:
                    </td>
                    <td>
                        <asp:Image ID="Image3" runat="server" ImageUrl ='<%# Eval("ValueForMoney")%>' style="width:80px;height:14px;"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        Acting Ability: 
                    </td>
                    <td>
                        <asp:Image ID="Image4" runat="server" ImageUrl ='<%# Eval("ActingAbility")%>' style="width:80px;height:14px;"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        Special Effects:
                    </td>
                    <td>
                        <asp:Image ID="Image5" runat="server" ImageUrl ='<%# Eval("SpecialEffects")%>' style="width:80px;height:14px;"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        Plot:
                    </td>
                    <td>
                        <asp:Image ID="Image6" runat="server" ImageUrl ='<%# Eval("Plot")%>' style="width:80px;height:14px;"/>
                    </td>
                </tr>
                </table>
            <table width="441px">
                <tr>
                    <td>
                        Reviewed By:
                    </td>
                    <td>
                        <%# Container.DataItem("Username")%>
                    </td>
                    <td>|</td>
                    <td>
                        <%# Container.DataItem("ReviewDate")%>
                    </td>
                    <td>|</td>
                    <td>
                        <%# Container.DataItem("ReviewerType")%> Review
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        Did you find this review helpful?&nbsp;&nbsp;&nbsp;<asp:Button ID="btnYes" runat="server" Text="Yes" />&nbsp;&nbsp;
                        <asp:Button ID="btnNo" runat="server" Text="No" /><br />
                        <asp:Label ID="lblResults" runat="server" Text="Total"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        <hr style="height:1px;border-bottom:none;color:#e3e3e3;"/>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:Repeater>

Open in new window


VB Code Behind
 
Dim total As Integer
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        doPaging()
    End Sub

 Function getTheData() As DataTable
        Dim DS As New DataSet()
        Dim strConnect As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " & _
        Server.MapPath("/App_Data/MovieBoard.accdb"))
        Dim objOleDBAdapter As New OleDbDataAdapter("Select MovieTitle, MovieImageFileName, ReviewText, ValueForMoney, ActingAbility, SpecialEffects, Plot, Total, Username, ReviewDate, ReviewerType From Movies, MovieReviews, MReviewRatings, MReviewTexts, UserDetails, ReviewerType WHERE Movies.MovieID = MovieReviews.MovieID AND MovieReviews.MReviewID = MReviewRatings.MReviewID AND MovieReviews.MReviewID = MReviewTexts.MReviewID AND MovieReviews.UserID = UserDetails.UserID AND MovieReviews.ReviewerTypeID = ReviewerType.ReviewerTypeID AND ReviewerType.ReviewerTypeID = 1", strConnect)
        objOleDBAdapter.Fill(DS, "Movies")

        Return DS.Tables("Movies").Copy
    End Function

Sub doPaging()
        pagedData.DataSource = getTheData().DefaultView
        pagedData.AllowPaging = True
        pagedData.PageSize = 1

        Try
            pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
        Catch ex As Exception
            pagedData.CurrentPageIndex = 0
        End Try

        btnPrev.Visible = False
        btnNext.Visible = False

        If Not pagedData.IsFirstPage Then
            btnPrev.PostBackUrl = Request.CurrentExecutionFilePath + _
                                           "?Page=" + CStr(pagedData.CurrentPageIndex - 1)
        End If

        If Not pagedData.IsLastPage Then
            btnNext.PostBackUrl = Request.CurrentExecutionFilePath + _
                                           "?Page=" + CStr(pagedData.CurrentPageIndex + 1)
        End If

        pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount

        movies.DataSource = pagedData
        movies.DataBind()
    End Sub

Protected Sub movies_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles movies.ItemCommand
        Dim yCount As Integer
        yCount = 0
        Dim nCount As Integer
        nCount = 0
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
        ListItemType.AlternatingItem Then
            Dim btnYes As Button = CType(e.Item.FindControl("btnYes"), Button)
            Dim btnNo As Button = CType(e.Item.FindControl("btnNo"), Button)
            Dim lblResults As Label = CType(e.Item.FindControl("lblResults"), Label)
            Dim sArgument As String = CType(e.Item.DataItem, 
                     DataRowView).Row.Item("MovieTitle").ToString
            If btnYes.OnClientClick Then
                yCount = yCount + 1
                MsgBox(yCount)
                lblResults.Text = yCount
            ElseIf btnNo.OnClientClick Then
                nCount = nCount + 1
            End If
            total = yCount + nCount

        End If
        MsgBox(total)
    End Sub

Open in new window

0
Comment
Question by:memecece
  • 6
  • 5
11 Comments
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38716532
Hi,

Why don't you keep the Yes and No buttons out of the Repeater Control?

You can always have a button and handle the OnClick event of the button!

Hope it helps u...
0
 
LVL 1

Author Comment

by:memecece
ID: 38716644
Hi roopesshreddy,

I had thought about that but then the button would only take a user click on one page. I need the buttons to be inside the repeater so that when the paging new yes/no buttons are available for a new review. Hope that makes sense
0
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 38716663
Hi,

Yeah! In that scenario,  you can reset the count on the Page Index Change right!

You can do the following -

1. Keep the Buttons outside of the Repeater control.
2. Handle the OnClick event.
3. Capture the reviews.
4. On Page Index change event, clear the previous reviews and hold the new one's

Hope it helps u...
0
 
LVL 1

Author Comment

by:memecece
ID: 38716670
Thank you :) It helps a lot. Just one more question how do I go about clearing the previous reviews? Sorry I only started using asp.net about 5 weeks ago so I'm still learning
0
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38716681
Hi,

How you are storing the review?
Are you using Sessions? If yes, then make it to NULL and re assign new values!
 If you are using the variables, then assign them to 0!

It totally depends on the way you are holding the data. In any case, make the values to 0 or NULL and you are done!

Hope it helps u...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:memecece
ID: 38716688
Thanks :) As I am using a repeater control I will need to find the equivalent to pageIndexChanging for that control - I'm pretty sure the repeater does not have this functionality.  Thanks for help
0
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38716705
Hi,

Check this article for Paging in Repeater control - http://www.4guysfromrolla.com/articles/081804-1.aspx

Hope it helps u...
0
 
LVL 1

Author Comment

by:memecece
ID: 38716708
Great thank you :) I got it working. You wouldn't by any chance know how I would be able to get the amount of data visible on each page to change depending on the number of reviews for a particular movie? For example for the Hobbit there might be 4 reviews but for Rise of the Guardians there is 3. This would mean that the page size would be 4 for the hobbit and change to 3 for the second movie. I have a function written that I call when determining my pagesize but it doesn't seem to change the size
0
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38716712
Hi,

Good Stuff!

Is everything OK now?
0
 
LVL 1

Author Comment

by:memecece
ID: 38716723
For that yes :)  Would you be able to suggest a solution for my other problem? - The page size issue?
0
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38716830
Hi,

Close this question and raise new one!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending E-mail ASP.Net 3 56
Hidden Field Value 10 60
Anyway to make "All" the default in the dropdown? 6 34
IIS issues - Convert to Application - APS.NET v4.0 3 23
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now