Click here to Skip to main content
15,921,840 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: SSRS 2005 in ASP.net Pin
DamithSL22-May-14 5:47
professionalDamithSL22-May-14 5:47 
GeneralRe: SSRS 2005 in ASP.net Pin
berba26-May-14 1:13
berba26-May-14 1:13 
QuestionWeb deployment task failed Pin
Sultan Uz Zaman21-May-14 5:35
Sultan Uz Zaman21-May-14 5:35 
AnswerRe: Web deployment task failed Pin
DamithSL21-May-14 17:20
professionalDamithSL21-May-14 17:20 
AnswerRe: Web deployment task failed Pin
jkirkerx28-May-14 12:24
professionaljkirkerx28-May-14 12:24 
QuestionCreating Multiple sheets in C# from html table and downloading Pin
Kandepu Rajesh20-May-14 20:50
Kandepu Rajesh20-May-14 20:50 
QuestionGPRS Data Logger to Website IP Pin
Member 1082292919-May-14 19:14
Member 1082292919-May-14 19:14 
QuestionMessage Closed Pin
18-May-14 23:37
Member 1082843918-May-14 23:37 
Questionhow to run event of asp contol by javascript code? Pin
alireza672518-May-14 5:41
alireza672518-May-14 5:41 
AnswerRe: how to run event of asp contol by javascript code? Pin
Anurag Gandhi22-May-14 4:19
professionalAnurag Gandhi22-May-14 4:19 
QuestionHow to convert speech to text? Pin
Member 1066162816-May-14 23:32
Member 1066162816-May-14 23:32 
AnswerRe: How to convert speech to text? Pin
Kornfeld Eliyahu Peter17-May-14 8:22
professionalKornfeld Eliyahu Peter17-May-14 8:22 
AnswerRe: How to convert speech to text? Pin
Richard MacCutchan17-May-14 21:11
mveRichard MacCutchan17-May-14 21:11 
QuestionFailed to map Path in Report Viewer Pin
Ravindra Bisen16-May-14 21:23
Ravindra Bisen16-May-14 21:23 
AnswerRe: Failed to map Path in Report Viewer Pin
ZurdoDev2-Jun-14 9:49
professionalZurdoDev2-Jun-14 9:49 
QuestionCode is not calculating percentages correctly. Pin
samflex16-May-14 7:57
samflex16-May-14 7:57 
Greetings Experts,

For the past two days now, I have been struggling with this code.

Our users had just finished using our online app to cast ballots and I have been trying to accomplish three things at same time.

One, display each candidate's name, his/her total vote count, and percentage of the vote s/he received.

With the code below, I am able to successfully display candidate's name and the total vote count for each candidate.

However, I have not been able to figure out how to display the percentage of each candidate's total vote count.

In the code shown below, if I run the sql portion of the code on Sql Server Management Studio, it works great.

However, when integrated with my .net portion of the code, it keeps assigning every candidate the same percentage of 100%.

I would really appreciate your expertise on this.

Thanks a in advance for your assistance.


VB
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim questionid As Integer
        questionid = CInt(CType(e.Item.FindControl("Label3"), Label).Text)
        Dim cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("BallotsConnectionString").ConnectionString)
        Dim cmd As New SqlCommand("select CandidateId, CASE WHEN CurrentOfficeHolder='Incumbent' THEN CandidateName + ' ('+ CurrentOfficeHolder + ')' ELSE CandidateName END As CandidateName from Candidates where PositionId=@qid", cnn)
        Dim p1 As New SqlParameter("@qid", questionid)
        cmd.Parameters.Add(p1)
        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        Dim ds As New DataSet
        da.Fill(ds, "choices")

        cnn.Open()
        For Each row As DataRow In ds.Tables("choices").Rows
            Dim cmdAns As New SqlCommand("select DISTINCT " & _
                                         "count( IsNull(er.candidateId,0)) OVER (Partition by o.orgName, p.Position, c.candidateName,p.PositionId ) " & _
                                         "as VoteCount, " & _
                                         "CAST(count( IsNull(er.candidateId,0)) OVER (Partition by o.orgName, p.Position, c.candidateName,p.PositionId ) *1./count( IsNull(er.candidateId,0)) OVER (Partition by p.Position)*100 as decimal(6,2)) as Percentage " & _
                                         "from Organizations o inner join Positions p on o.OrgID = p.OrgID inner join Candidates c on p.positionId = c.positionId " & _
                                         "inner join ElectionResults er on c.candidateId = er.candidateId " & _
                                         "WHERE c.candidateid = @cid", cnn)
            Dim pCid As New SqlParameter("@cid", row("candidateid"))
            cmdAns.Parameters.Add(pCid)

            Dim dr = cmdAns.ExecuteReader()
            If dr.HasRows = True Then
                While dr.Read
                    Dim count As Integer = dr(0)
                    Dim pct As String = dr(1)
                    row("CandidateName") = row("CandidateName") & " - " & count & "(" & pct & "%)"
                End While
            End If
            dr.Close()

        Next
        cnn.Close()
        Dim list As BulletedList = e.Item.FindControl("BulletedList1")
        list.DataSource = ds
        list.DataTextField = "CandidateName"
        list.DataBind()
    End If

End Sub

AnswerRe: Code is not calculating percentages correctly. Pin
jkirkerx16-May-14 11:49
professionaljkirkerx16-May-14 11:49 
GeneralRe: Code is not calculating percentages correctly. Pin
samflex16-May-14 13:18
samflex16-May-14 13:18 
GeneralRe: Code is not calculating percentages correctly. Pin
jkirkerx16-May-14 13:24
professionaljkirkerx16-May-14 13:24 
GeneralRe: Code is not calculating percentages correctly. Pin
samflex16-May-14 15:19
samflex16-May-14 15:19 
GeneralRe: Code is not calculating percentages correctly. Pin
jkirkerx16-May-14 16:26
professionaljkirkerx16-May-14 16:26 
QuestionPaging Dynamic Data in a Gridview Pin
Grajek15-May-14 7:47
Grajek15-May-14 7:47 
AnswerRe: Paging Dynamic Data in a Gridview Pin
Praneet Nadkar15-May-14 22:04
Praneet Nadkar15-May-14 22:04 
Questionlink button click event not firing for dynamically added link button Pin
Member 1071882015-May-14 4:59
Member 1071882015-May-14 4:59 
AnswerRe: link button click event not firing for dynamically added link button Pin
Kornfeld Eliyahu Peter15-May-14 6:51
professionalKornfeld Eliyahu Peter15-May-14 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.