綁定值添加您的變量爲multi-dimensional array
。
然後將該數組綁定到DataTable
。
代碼
int cnt = Convert.ToInt32(txtCount.Text);
DateTime start = Convert.ToDateTime(txtStart.Text);
DateTime end = Convert.ToDateTime(txtEnd.Text);
TimeSpan datedifference = end.Subtract(start);
int dateCount = datedifference.Days;
float maxUpload = dateCount * 288;
float remainingUpload = maxUpload - cnt;
float averageUpload = remainingUpload/(dateCount * 288) * 100;
string[,] row1 = { { dateCount.ToString(), maxUpload.ToString(), remainingUpload .ToString(), averageUpload .ToString() } };
DataTable table = new DataTable();
table.Columns.Add("DateCount", typeof(string));
table.Columns.Add("maxUpload", typeof(string));
table.Columns.Add("remainingUpload", typeof(string));
table.Columns.Add("averageUpload", typeof(string));
for (int i = 0; i <= row1.GetUpperBound(0); i++)
{
table.Rows.Add();
table.Rows[i]["DateCount"] = row1[i, 0];
table.Rows[i]["maxUpload"] = row1[i, 1];
table.Rows[i]["remainingUpload"] = row1[i, 2];
table.Rows[i]["averageUpload"] = row1[i, 3];
}
gridview1.DataSource = table;
gridview1.DataBind();
源代碼
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="true">
</asp:GridView>
而且不要忘了添加此namespace
也。
using System.Data;
所以你'Gridview'將只有1行? – Wanderer
@Ullas:是的...... – Reshma
@Reshma如果只有一行比爲什麼要使用gridview?只需要創建html表格並在html表格的td中放置四個標籤 – Sandeep