Well, I've got my data just fine. I just need the data, and I'll then run a stored procedure to update the values, THEN re-query it. Here's most of the code-behind. I'm still learning .NET, so it's a bit ungainly. I plan on parsing out a good bit of it to other components. It wouldn't let me post the whole thing.
-
protected void InitDataTable(DataTable dt)
-
{
-
DataColumn dcol = new DataColumn("Doff Number", typeof(System.Int64));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("Length", typeof(System.Int64));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("Doff Length", typeof(System.Int64));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("Start Time", typeof(System.DateTime));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("End Time", typeof(System.DateTime));
-
dt.Columns.Add(dcol);
-
dcol = new DataColumn("WeavingDoffId", typeof(System.Guid));
-
dt.Columns.Add(dcol);
-
}
-
-
protected void LoadDataTable(DataTable dt)
-
{
-
CMetalsWeavingDoffs cmwd = new CMetalsWeavingDoffs();
-
-
LoadMetalsWeavingDoffs(cmwd);
-
foreach (SMetalsWeavingDoffs smwd in cmwd)
-
{
-
DataRow drow = dt.NewRow();
-
drow["Doff Number"] = smwd.WeavingDoffNumber;
-
drow["Length"] = smwd.Length;
-
drow["Doff Length"] = GetDoffLength(smwd.WorkOrderActualId);
-
drow["Start Time"] = smwd.StartTime;
-
drow["End Time"] = smwd.EndTime;
-
drow["WeavingDoffId"] = smwd.WeavingDoffId;
-
dt.Rows.Add(drow);
-
}
-
}
-
-
protected void InitGrid(DataTable dt)
-
{
-
ButtonField confirmField = new ButtonField();
-
ButtonField scrapField = new ButtonField();
-
CommandField editField = new CommandField();
-
-
if (!Page.IsPostBack)
-
{
-
foreach (DataColumn col in dt.Columns)
-
{
-
BoundField bfield = new BoundField();
-
bfield.DataField = col.ColumnName;
-
bfield.HeaderText = col.ColumnName;
-
if (bfield.DataField != "WeavingDoffId")
-
grdDynamic.Columns.Add(bfield);
-
if (bfield.DataField != "Length")
-
bfield.ReadOnly = true;
-
}
-
confirmField.HeaderText = "Confirm";
-
confirmField.Text = "Confirm";
-
confirmField.CommandName = "Confirm";
-
confirmField.ButtonType = ButtonType.Button;
-
grdDynamic.Columns.Add(confirmField);
-
scrapField.HeaderText = "Scrap";
-
scrapField.Text = "Scrap";
-
scrapField.CommandName = "Scrap";
-
scrapField.ButtonType = ButtonType.Button;
-
grdDynamic.Columns.Add(scrapField);
-
editField.HeaderText = "Edit";
-
editField.EditText = "Edit Length";
-
editField.UpdateText = "Update";
-
editField.CancelText = "Cancel";
-
editField.ButtonType = ButtonType.Button;
-
editField.ShowEditButton = true;
-
editField.CausesValidation = false;
-
grdDynamic.Columns.Add(editField);
-
-
}
-
grdDynamic.DataSource = dt;
-
grdDynamic.DataBind();
-
}
-
-
protected void CreateGrid()
-
{
-
string[] dataKeyNames = new string[2];
-
-
grdDynamic.AutoGenerateColumns = false;
-
grdDynamic.SkinID = "MainGridView";
-
grdDynamic.RowCommand += new GridViewCommandEventHandler(grdDynamic_RowCommand);
-
grdDynamic.RowEditing += new GridViewEditEventHandler(grdDynamic_RowEditing);
-
grdDynamic.RowCancelingEdit += new GridViewCancelEditEventHandler(grdDynamic_RowCancelEditing);
-
grdDynamic.RowUpdating += new GridViewUpdateEventHandler(grdDynamic_RowUpdating);
-
dataKeyNames[0] = "WeavingDoffId";
-
dataKeyNames[1] = "Length";
-
if (!Page.IsPostBack)
-
grdDynamic.DataKeyNames = dataKeyNames;
-
Page.Form.Controls.Add(grdDynamic);
-
}
-
-
protected void BindGrid()
-
{
-
DataTable dt = new DataTable();
-
-
try
-
{
-
InitDataTable(dt);
-
LoadDataTable(dt);
-
InitGrid(dt);
-
}
-
catch(Exception ex)
-
{
-
lblError.Text += ex.Message;
-
}
-
}
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
Response.Expires = -1600;
-
lblError.Text = string.Empty;
-
CreateGrid();
-
if (!Page.IsPostBack)
-
BindGrid();
-
}
-
-
protected void grdDynamic_RowCommand(object sender, GridViewCommandEventArgs e)
-
{
-
try
-
{
-
if (e.CommandName == "Confirm")
-
{
-
ConfirmDoff(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString(), Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["Length"]));
-
ConfirmDoffOld(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString());
-
}
-
if (e.CommandName == "Scrap")
-
ScrapDoff(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["WeavingDoffId"].ToString(), Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["Length"]));
-
BindGrid();
-
}
-
catch (Exception ex)
-
{
-
lblError.Text = ex.Message;
-
}
-
}
-
-
protected void grdDynamic_RowEditing(object sender, GridViewEditEventArgs e)
-
{
-
grdDynamic.EditIndex = e.NewEditIndex;
-
BindGrid();
-
}
-
-
protected void grdDynamic_RowCancelEditing(object sender, GridViewCancelEditEventArgs e)
-
{
-
grdDynamic.EditIndex = -1;
-
BindGrid();
-
}
-
-
protected void grdDynamic_RowUpdating(object sender, GridViewUpdateEventArgs e)
-
{
-
Guid weavingDoffId = new Guid(grdDynamic.DataKeys[Convert.ToInt32(e.RowIndex)].Values["WeavingDoffId"].ToString());
-
//DataControlFieldCell cell = new DataControlFieldCell(grdDynamic.Rows[e.RowIndex].Cells[0]);
-
-
grdDynamic.EditIndex = -1;
-
lblError.Text = "I do the update on " + e.OldValues.Count + "! Huzzah!";
-
//DataControlFieldCell cell = grdDynamic.Rows[e.RowIndex].Cells[1] as DataControlFieldCell;
-
//grdDynamic.Columns[1].ExtractValuesFromCell(e.OldValues, cell, DataControlRowState.Edit, true);
-
//lblError.Text = e.OldValues[0].ToString();
-
//lblError.Text = grdDynamic.Rows[0].Cells[0].Controls[0].ToString();
-
//TextBox newBox = (TextBox)grdDynamic.Rows[0].Cells[1].Controls[0];
-
//lblError.Text = newBox.Text;
-
try
-
{
-
//UpdateLength(weavingDoffId, Convert.ToInt32(grdDynamic.DataKeys[Convert.ToInt32(e.RowIndex)].Values["Length"]));
-
}
-
catch (Exception ex)
-
{
-
lblError.Text = ex.Message;
-
}
-
BindGrid();
-
}
-
-
protected void btnRefresh_Click(object sender, EventArgs e)
-
{
-
BindGrid();
-
}
-
}
-
The HTML is very sparse:
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>Metals Doff Confirmation</title>
-
<link href="PMDStyles.css" rel="stylesheet" type="text/css" />
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div style="text-align: center;">
-
Click here to
-
<asp:Button ID="btnRefresh" runat="server" Text="Refresh"
-
onclick="btnRefresh_Click" />
-
the page.
-
</div>
-
<hr />
-
<div style="text-align: center;">
-
<div style="text-align: center;">
-
<asp:Label ID="lblError" runat="server"></asp:Label>
-
</div>
-
</form>
-
</body>
-
</html>
-
The main problem I'm having is with the grdDynamic_RowUpdating subroutine. I can get the current value all I want to. The commented lines are my various attempts to read the NEW data that the user inputs. None of them will retrieve anything but the old data.
The Confirm and Scrap commands all work fine, as do my refresh and display routines. The ONLY thing that won't return is the new data.