|
|
|
Web (ASP.NET C#) เลือกเปลี่ยนปีใน DropDownList แล้วข้อมูลไม่ยอมเปลี่ยนตามคับ |
|
|
|
|
|
|
|
คือเลือก DropDownList แล้วข้อมูลไม่ยอมเปลี่ยนตามปีที่เลือกคับ
Code (ASP)
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<br />
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<asp:GridView ID="gvData" runat="server">
</asp:GridView>
<br />
<br />
<asp:Literal ID="ltScripts" runat="server"></asp:Literal>
<div id="chart_div" style="width: 660px; height: 400px;">
</div>
</div>
</asp:Content>
Code (C#)
#region " [ Using ] "
using System;
using System.Web.UI;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
#endregion
namespace WebApplication4
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add(new ListItem("2016", "2016"));
DropDownList1.Items.Add(new ListItem("2015", "2015"));
DropDownList1.Items.Add(new ListItem("2014", "2014"));
// Bind Gridview
BindGvData();
// Bind Charts
BindChart();
}
}
private void BindGvData()
{
gvData.DataSource = GetChartData();
gvData.DataBind();
}
private void BindChart()
{
DataTable dsChartData = new DataTable();
StringBuilder strScript = new StringBuilder();
try
{
dsChartData = GetChartData();
strScript.Append(@"<script type='text/javascript'>
google.load('visualization', '1', {packages: ['corechart']});</script>
<script type='text/javascript'>
function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['week', 'OpenQty', 'ConfirmQty'],");
foreach (DataRow row in dsChartData.Rows)
{
strScript.Append("['" + row["week"] + "'," + row["OpenQty"] + "," +
row["ConfirmQty"] + "],");
}
strScript.Remove(strScript.Length - 1, 1);
strScript.Append("]);");
strScript.Append("var options = { title : 'PO Open And Confrim ', vAxis: {title: 'Qty'}, hAxis: {title: 'week'}, seriesType: 'bars' };");//กำหนดชื่อต่างๆ
strScript.Append(" var chart = new google.visualization.ComboChart(document.getElementById('chart_div')); chart.draw(data, options); } google.setOnLoadCallback(drawVisualization);");
strScript.Append(" </script>");
ltScripts.Text = strScript.ToString();
}
catch
{
}
finally
{
dsChartData.Dispose();
strScript.Clear();
}
}
/// <summary>
/// fetch data from mdf file saved in app_data
/// </summary>
/// <returns>DataTable</returns>
public DataTable GetChartData()
{
DataSet dsData = new DataSet();
try
{
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["SVI_MMmoduleEntities"].ConnectionString);
SqlCommand cmd = new SqlCommand("data_week", sqlCon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Year", Int32.Parse(DropDownList1.SelectedValue));
SqlDataAdapter sqlCmd = new SqlDataAdapter(cmd);
sqlCon.Open();
sqlCmd.Fill(dsData);
sqlCon.Close();
}
catch
{
throw;
}
return dsData.Tables[0];
}
}
}
Tag : Ms SQL Server 2012, HTML/CSS, Web (ASP.NET)
|
|
|
|
|
|
Date :
2016-11-01 15:55:43 |
By :
panupan2550 |
View :
669 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|