Datagrid - paging
When autogeneratecolumns=true, paging works fine but the columns displayed are not what I want.
When autogeneratecolumns=false, the wgWellLog_PageIndexChanged event handler is never invoked and the "next page" is blank.
---------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using adminServices = FCS.BeaconResources.AdminServices.clsAdminServices ;
using dbServices = FCS.BeaconResources.WellLogDBServices.WellLogDBSer vices;
namespace FCS.BeaconResources
{
/// <summary>
/// Summary description for DisplayWellData.
/// </summary>
public class DisplayWellData : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgWellLog;
public DataSet leDS;
enum DGCol :int
{
MMDD,
Time,
ChokeSize,
TubingPressure,
CasingPressure,
MeterPSIG,
MeterDiff,
MeterTemp,
OrificeSize,
WaterFlow,
WaterAccum,
OilFlow,
OilAccum,
InjectionRate,
InjectionCum,
SalesRate,
SalesCum,
YesterdaySales,
Remarks
}
private void Page_Load(object sender, System.EventArgs e)
{
if (Session["LoggedIn"] == null)
Session.Add("LoggedIn", false);
if ((bool)Session["LoggedIn"])
{
bool IsSiteDown;
string SiteMessage;
new adminServices().SiteStateGet(out IsSiteDown,out SiteMessage);
if(IsSiteDown)
{
Server.Transfer("SiteDown.aspx");
}
else
{
if (!IsPostBack)
{
BindData();
}
}
}
else
{
Response.Redirect("../Default.htm");
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgWellLog.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.dgWellLog_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private BoundColumn CreateNewBoundColumn(string Field, string ColHeader)
{
BoundColumn BC = new BoundColumn();
BC.DataField = Field;
BC.HeaderText = ColHeader;
return BC;
}
protected void BindData()
{
dgWellLog.Columns.Add(CreateNewBoundColumn("MMDD", "Date"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Time", "Time"));
dgWellLog.Columns.Add(CreateNewBoundColumn("ChokeS izeText","Choke Size (/64)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Tubing Pressure","Tbg PSIG"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Casing Pressure","Csg PSIG"));
dgWellLog.Columns.Add(CreateNewBoundColumn("MeterP SIG","Line PSIG"));
dgWellLog.Columns.Add(CreateNewBoundColumn("MeterD iff","Diff PSIG"));
dgWellLog.Columns.Add(CreateNewBoundColumn("MeterT emp","Temp"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Orific eSize","Orif. Size"));
dgWellLog.Columns.Add(CreateNewBoundColumn("WaterF low","H2O (Bbls)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("WaterA ccum","H2O Cum (Bbls)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("OilFlo w","Oil(Bbls)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("OilAcc um","Oil Cum Bbls)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Inject ionRate","Inj Rate (MCFPD)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Inject ionCum","Inj Cum (MCF)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("SalesR ate","Sales Rate (MCFPD)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("SalesC um","Sales Cum (MCF)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Yester daySales","Yesterday Sales (MCF)"));
dgWellLog.Columns.Add(CreateNewBoundColumn("Remark s","Remarks"));
foreach (DataGridColumn c in dgWellLog.Columns)
{
c.HeaderStyle.BorderColor=Color.Black;
c.HeaderStyle.BorderWidth=1;
c.ItemStyle.BorderColor=Color.Black;
c.ItemStyle.BorderWidth=1;
}
dgWellLog.Columns[(int)DGCol.Remarks].HeaderStyle.HorizontalAlign=HorizontalAlign.Left;
dgWellLog.Columns[(int)DGCol.Remarks].ItemStyle.HorizontalAlign=HorizontalAlign.Left;
dbServices DBServices = new dbServices();
leDS = DBServices.LogEntriesGet(((clsWorkOrder)Session["WorkOrder"]).WorkOrder_Key);
DataColumn dc = new DataColumn("WaterAccum",System.Type.GetType("Syste m.Double"));
leDS.Tables["tblLogEntries"].Columns.Add(dc);
dc = new DataColumn("OilAccum",System.Type.GetType("System. Double"));
leDS.Tables["tblLogEntries"].Columns.Add(dc);
dc = new DataColumn("MMDD",System.Type.GetType("System.Stri ng"));
leDS.Tables["tblLogEntries"].Columns.Add(dc);
dc = new DataColumn("Time",System.Type.GetType("System.Stri ng"));
leDS.Tables["tblLogEntries"].Columns.Add(dc);
dc = new DataColumn("ChokeSizeText",System.Type.GetType("Sy stem.String"));
leDS.Tables["tblLogEntries"].Columns.Add(dc);
double mOilCum = 0;
double mWaterCum = 0;
foreach (DataRow r in leDS.Tables["tblLogEntries"].Rows)
{
int CS = (int)((double)r["ChokeSize"]);
switch (CS)
{
case -1:
r["ChokeSizeText"] = "ShtIn";
break;
case 192:
r["ChokeSizeText"] = "WidOpn";
break;
default:
r["ChokeSizeText"] = ((double)r["ChokeSize"]).ToString();
break;
}
r["MMDD"] = ((DateTime)r["DateAndTime"]).ToString("MM/dd");
r["Time"] = ((DateTime)r["DateAndTime"]).ToString("HH:mm");
mWaterCum += (double)r["WaterFlow"];
r["WaterAccum"] = mWaterCum;
mOilCum += (double)r["OilFlow"];
r["OilAccum"] = mOilCum;
}
dgWellLog.DataSource=leDS.Tables["tblLogEntries"];
dgWellLog.DataBind();
}
private void dgWellLog_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
dgWellLog.CurrentPageIndex = e.NewPageIndex;
BindData();
}
}
}
ferg
|