我的问题,我有两个存储过程,一个是调用数据填充下拉列表,另一个是填充我的gridview。我需要的是当我从下拉列表中选择一个项目时,页面应该刷新并用新数据更新gridview。但我遇到的问题是,每次回发后都会出现相同的数据和页面,所以它不会提取新数据......我的选择值有一个硬编码值,但我也需要把它拿出去,以便当用户选择时一个项目然后它会自动更新......
namespace WorkStationUITarget
{
public partial class Default : System.Web.UI.Page
{
//public static int CountLabel = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Refreshdata(225);
BindDropDownList();
}
}
private void BindDropDownList()
{
BizManager mgr = new BizManager();
DropDownList1.DataSource =
mgr.GetItemSeriesMaster(); //.DefaultView.RowFilter("ID = 201"); //how to filter data
DropDownList1.DataTextField = "DESCRIPTION"; // the items to be displayed in the list items
DropDownList1.DataValueField = "ID"; // the id of the items displayed
DropDownList1.DataBind();
}
public void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
//refreshes to the new table on drop selection
}
public void Refreshdata(int selectedProduct)
{
BizManager biz = new BizManager();
GridView1.DataSource = biz.GetPacktstatisticsForShift(new DateTime(2016, 6, 10, 6, 0, 0)
, new DateTime(2016, 6, 10, 13, 59, 59)
, selectedProduct).DefaultView;
GridView1.DataBind();
//rebind the data
}
public class BizManager
{
public string Shiftstart { get; set; }
public string Shiftend { get; set; }
public string Itemseriesmaster { get; set; }
public string SeriesMasterId { get; set; }
public DataTable GetPacktstatisticsForShift(DateTime shiftStart, DateTime shiftEnd, int seriesMasterId)
{
using (DataManager dmgr = new DataManager())
{
dmgr.Connect(ConfigurationManager.AppSettings["ProductionKey"]);
DataSet dset = dmgr.TargetQuantites(seriesMasterId, shiftStart, shiftEnd);
return CreatePackingStats(dset);
}
}
public DataTable GetItemSeriesMaster()
{
using (DataManager dmgr = new DataManager())
{
dmgr.Connect(ConfigurationManager.AppSettings["ProductionKey"]);
DataSet dset = dmgr.getworkstationnames();//IManSeriesList();
return dset.Tables[0];
}
}
public DataTable CreatePackingStats(DataSet dset)
{
using (DataManager dmgr = new DataManager())
{
DataTable target = dset.Tables[0];
DataTable actual = dset.Tables[1];
DataColumn[] cols = new DataColumn[1];
cols[0] = actual.Columns["Hour"];
actual.PrimaryKey = cols;
DataTable final = new DataTable();
// Create table columns
foreach (DataColumn col in target.Columns)
{
final.Columns.Add(new DataColumn(col.ColumnName, col.DataType));
if (col.ColumnName.Contains("Target"))
{
// Add an equivilant actual column
string newColumnName = col.ColumnName.Replace("Target", "Actual");
final.Columns.Add(newColumnName, col.DataType);
}
}
//// Add rows to new table
foreach (DataRow row in target.Rows)
{
string key = row["Hour"].ToString();
DataRow newRow = final.Rows.Add();
// Store column value
foreach (DataColumn col in final.Columns)
{
if (col.ColumnName.Contains("HOUR") || col.ColumnName.Contains("Target"))
{
newRow[col.ColumnName] = row[col.ColumnName];
}
else
{
// Find actual data
DataColumn actColumn = actual.Columns[col.ColumnName] as DataColumn;
if (actColumn == null)
{
newRow[col.ColumnName] = 0;
}
else
{
if (string.IsNullOrEmpty(actual.Rows.Find(key)[col.ColumnName].ToString()))
{
newRow[col.ColumnName] = 0;
}
else
{
newRow[col.ColumnName] = actual.Rows.Find(key)[col.ColumnName].ToString();
}
}
}
}
}
return final;
}
}
}
}
namespace WorkStationUITarget.Data
{
public partial class DataManager : DataLayer
{
public DataSet TargetQuantites(int itemSeriesMasterId, DateTime shiftstart, DateTime shiftend)
{
object[] args = new object[3] { itemSeriesMasterId, shiftstart, shiftend };
return CallSp(MethodBase.GetCurrentMethod(), args) as DataSet;
} // CALLS A STORED PROC
public DataSet getworkstationnames() //IManSeriesList() //CHANGE BACK FOR OTHER USP
{
object[] args = new object[] {} ;
return CallSp(MethodBase.GetCurrentMethod(), args) as DataSet;
}
}
}
@Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WorkStationUITarget.Default" %>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="CSS/style.css" rel="stylesheet" />
<style>
body {
font-family: Arial;
color: white;
}
.split {
height: 100%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: #110;
width: 30%;
text-align: center;
}
.right {
right: 0;
background-color: white;
width: 70%;
position: fixed;
text-align: center;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.centered img {
width: 150px;
border-radius: 50%;
}
</style>
</head>
<body>
<div class="split left">
<div class="center">
<h1 style="color: red; font-weight: bold; position: static; text-align: center; padding-top: 25px "> TOTAL QUANTITY PACKED
<asp:Label ID="label" runat="server" Text="1" Width="100%" Height="100%" Font-Size="250px" style="position: static; text-align: center; padding-top: 280px; "></asp:Label>
<img src="Logo/siemensblack1.png" style="position: static; top: 110px; padding-top: 300px"; />
</div>
<div class="body-container;">
</div>
</div>
<form runat="server">
<div class="split right">
<div class="center">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" align="centered" OnSelectedIndexChanged="Dropdownlist1_SelectedIndexChanged" >
<asp:ListItem Value="214">214</asp:ListItem>
<asp:ListItem Value="225">225</asp:ListItem>
</asp:DropDownList>
<h1 style="color: red; font-weight: bold; text-align: center;">CELL TARGETS & ACTUAL FIGURES</h1>
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="black" BorderStyle="None" BorderWidth="5px" CellPadding="25" ForeColor="Black" GridLines="Horizontal" HorizontalAlign="Center" Font-Size="24px" >
<AlternatingRowStyle BackColor="White"/>
<FooterStyle BackColor="#CCCC99"/>
<HeaderStyle BackColor="white" Font-Bold="True" ForeColor="black"/>
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right"/>
<RowStyle BackColor="#F7F7DE"/>
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="black"/>
<SortedAscendingCellStyle BackColor="#FBFBF2"/>
<SortedAscendingHeaderStyle BackColor="#848384"/>
<SortedDescendingCellStyle BackColor="#EAEAD3"/>
<SortedDescendingHeaderStyle BackColor="#575357"/>
</asp:GridView>
<div class="w3-container">
<div class="center">
<style>
div { padding: 30px 10px 15px; }
.newStyle1 {
color: #FF0000;
font-size: 86px;
}
</style>
</div>
<img src="Logo/siemenswhite1.png" style="padding-left: 70px; padding-top: 13px; position: static; text-align: center;"/>
</div>
</div>
</div>
</form>
</body>
</html>
我认为它必须与页面后面的aspx代码有关。
答案 0 :(得分:1)
您只需使用所选的产品ID并将其传递给Refreshdata
:
public void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
int productId;
if(int.TryParse(Dropdownlist1.SelectedValue, out productId))
Refreshdata(productId);
}