我正在處理一個網頁,該網頁可以提取用戶分數並將分數提高到一個百分比。然後使用百分比使用width和aria-valuenow來填充Bootstrap進度條。ASPX頁面上的C#值在刷新時結合在一起
問題是,在初始構建和頁面刷新後,進度條寬度(又稱分數)隨原始分數增加。例如,如果百分比從40開始,它將刷新爲80 ... 120 ... 160 ...等。
下面是C#代碼,我分配的值:例如起見
private static string[][] matches = new string[numOfGames][];
private static string[] winningTeams = new string[numOfGames];
protected static string[,] players = { { "Name", "0" }, { "Name", "0" }, { "Name", "0" }, { "Name", "0" }, { "Name", "0" }, { "Name", "0" }, { "Name", "0" }, { "Name", "0" }, { "Name", "0" } };
public static double score_name1, score_name2, score_name3, score_name4, score_name5, score_name6, score_name7, score_name8, score_name9;
protected void Page_Load(object sender, EventArgs e) {
gatherMatches();
DataTable userPicks = getGSheetData();
userPicks.Columns.Remove("Timestamp");
userPicks.Columns.Remove("Your Name");
convertTeamNames();
compareMatches();
generateUserScores(userPicks);
score_name1 = Convert.ToDouble(players[0, 1])/numOfGames * 100.00;
score_name2 = Convert.ToDouble(players[1, 1])/numOfGames * 100.00;
score_name3 = Convert.ToDouble(players[2, 1])/numOfGames * 100.00;
score_name4 = Convert.ToDouble(players[3, 1])/numOfGames * 100.00;
score_name5 = Convert.ToDouble(players[4, 1])/numOfGames * 100.00;
score_name6 = Convert.ToDouble(players[5, 1])/numOfGames * 100.00;
score_name7 = Convert.ToDouble(players[6, 1])/numOfGames * 100.00;
score_name8 = Convert.ToDouble(players[7, 1])/numOfGames * 100.00;
score_name9 = Convert.ToDouble(players[8, 1])/numOfGames * 100.00;
name2.Attributes.Add("style", "width: " + score_name2.ToString() + "%");
name2.Attributes.Add("aria-valuenow", players[0, 1].ToString());
}
代替實際名稱的值。
而在ASPX頁面:
<%@ Page Title="Scoreboard" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Scoreboard.aspx.cs" Inherits="Football.Scoreboard" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="page-header">
<h2><%: Title %></h2>
<h3>See up to date standings.</h3>
</div>
<p>This page can be refreshed during game time to see changes in leaders as they happen.</p>
<div class="row">
<div class="col-md-6">
<h3>This Week</h3>
<div class="progress">
<div id="name1" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="5" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Name
</div>
</div>
<div class="progress">
<div id="name2" runat="server" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="16">
Name
</div>
</div>
<div class="progress">
<div id="name3" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="4" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Name
</div>
</div>
<div class="progress">
<div id="name4" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="3" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Jen
</div>
</div>
<div class="progress">
<div id="name5" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Name
</div>
</div>
<div class="progress">
<div id="name6" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Name
</div>
</div>
<div class="progress">
<div id="name7" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Ryan
</div>
</div>
<div class="progress">
<div id="name8" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Name
</div>
</div>
<div class="progress">
<div id="name9" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="16" style="width: 0%">
Name
</div>
</div>
</div>
我只應用了行動,第二個進度條,因爲別人在目前沒有數據。
提供了更多關於該頁面的代碼......沒有足夠的信息來推斷該問題。 – scartag 2014-10-29 06:01:27
你是指aspx頁面還是cs頁面? – lostchopstik 2014-10-29 06:11:04