Hello
I am having problems extracting the OldValues collection from the RowUpdating event in my GridView.
Every time I access this I am getting the values from the NewValues collection in both OldValues and NewValues. I am fairly sure that the data is not being rebound prior to the updating event.
I have posted my code below.
Thanks in advance.
I am having problems extracting the OldValues collection from the RowUpdating event in my GridView.
Every time I access this I am getting the values from the NewValues collection in both OldValues and NewValues. I am fairly sure that the data is not being rebound prior to the updating event.
I have posted my code below.
Thanks in advance.
Code:
<asp:Panel ID="pnlShowDelays" runat="server" Visible="true" CssClass="pnlLJDel">
<div id="div1" class="divDelays">
<asp:GridView ID="gvDelays" runat="server" GridLines="None" CellSpacing="1" DataKeyNames="id"
OnRowCancelingEdit="gvDelays_RowCancelingEdit" OnRowEditing="gvDelays_RowEditing"
OnRowUpdating="gvDelays_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Note Text">
<EditItemTemplate>
<asp:TextBox Font-Size="8pt" ID="txComm" TextMode="multiLine" runat="server" Text='<%# Bind("note_type_description") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblComm" Font-Size="8pt" runat="server" Text='<%# Eval("note_type_description") %>'></asp:Label>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" HorizontalAlign="Left" />
</asp:TemplateField>
<asp:CommandField HeaderText="Edit/Update" ButtonType="Image" ShowEditButton="True"
CancelImageUrl="~/images/RowCancel.gif" EditImageUrl="~/images/RowEdit.gif" UpdateImageUrl="~/images/RowUpdate.gif" />
</Columns>
<FooterStyle CssClass="gridViewFooterStyle" />
<RowStyle CssClass="gridViewRowStyle" />
<EditRowStyle CssClass="gridEditRowStyle" />
<SelectedRowStyle CssClass="gridViewSelectedRowStyle" />
<PagerStyle CssClass="gridViewPagerStyle" HorizontalAlign="Center" />
<HeaderStyle CssClass="gridViewHeaderStyle" />
<AlternatingRowStyle CssClass="gridViewAlternatingRowStyle" />
</asp:GridView>
</div>
</asp:Panel>
public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
loadGrid();
}
}
protected void loadGrid()
{
SQLCons sq = new SQLCons();
Note_types nt = new Note_types();
nt.Get_NOTE_TYPES();
loadDelay(nt.RetDataSet);
}
protected void BindData()
{
gvDelays.DataSource = null;
gvDelays.DataBind();
gvDelays.DataSource = (DataSet)Session["dsDelays"];
gvDelays.DataBind();
}
protected void loadDelay(DataSet ds)
{
Session["dsDelays"] = ds;
BindData();
}
protected void gvDelays_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataControlFieldCell NewCell = gvDelays.Rows[e.RowIndex].Cells[0] as DataControlFieldCell;
gvDelays.Columns[0].ExtractValuesFromCell(
e.NewValues,
NewCell,
DataControlRowState.Edit,
true);
gvDelays.Columns[0].ExtractValuesFromCell(
e.OldValues,
NewCell,
DataControlRowState.Edit,
true);
foreach (string key in e.OldValues.Keys)
{
string s = e.OldValues[key].ToString();
}
foreach (string key in e.NewValues.Keys)
{
string s = e.NewValues[key].ToString();
}
}
protected void gvDelays_RowEditing(object sender, GridViewEditEventArgs e)
{
gvDelays.EditIndex = e.NewEditIndex;
BindData();
}
protected void gvDelays_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvDelays.EditIndex = -1;
BindData();
}
}