Hi,
I am facing a strange behavior which I am not able to find the solution.
I have a Gridview to show data from my database and after click on Edit, I will allow certain fields to be modified.
However, when I click Update, some of the fields not able to accept the new value and some field are taking new values + old values, thus making it wrong.
Let's say, my txtComments original data is empty string.
Now, I click Edit, and Update without modifying the data in txtComments, I will get ",,"
Then I click Edit again and Update without modifying the data in txtComments, I will get ",,,,,,,,"
Let's say, my txtComments original data is "123"
Now, I click Edit, and Update without replace the data in txtComments to 456, I will get 456,123,123
Other than that I am not able to read new value for txtOverrideMin, txtOverrideMin, txtOverrideMax
It is pretty strange and I try to debug it and see where the values are from, some how no avail.
Here are some of my codes, I hope you can spot where it goes wrong.
Thanks for any assistance.
protected void gvList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvList.EditIndex = -1;
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
protected void gvList_RowEditing(object sender, GridViewEditEventArgs e)
{
gvList.EditIndex = e.NewEditIndex;
PopulateFilters(this.DataContext);
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
protected void gvList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtOverride = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtOverride");
TextBox txtOverrideMin = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtOverrideMin");
TextBox txtOverrideMax = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtOverrideMax");
TextBox txtComments = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtComments");
TextBox txtDistyModel = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtDistyModel");
TextBox txtcustomer = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtcustomer");
TextBox txtOPN = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtopn");
Int32.TryParse(txtOverride.Text, out Qty_override);
Int32.TryParse(txtOverrideMin.Text, out Qty_override_min);
Int32.TryParse(txtOverrideMax.Text, out Qty_override_max);
comments = txtComments.Text;
customer = txtcustomer.Text;
opn = txtOPN.Text;
distymodel = txtDistyModel.Text;
try
{
DataAccess.EditCustomerBuffer(
"Edit",
distymodel,
customer,
opn,
Qty_override,
Qty_override_min,
Qty_override_max,
comments);
gvList.EditIndex = -1;
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
catch (Exception ex)
{
error = getErrorMessage(ex.Message);
ScriptManager.RegisterClientScriptBlock(
this,
this.GetType(),
"ERROR:Edit",
"alert('" + error + "');",
true);
}
}
protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lbldistymodel = (Label)gvList.Rows[e.RowIndex].FindControl("lbldistymodel");
Label lblOPN = (Label)gvList.Rows[e.RowIndex].FindControl("lblOPN");
Label lblcustomer = (Label)gvList.Rows[e.RowIndex].FindControl("lblcustomer");
opn = lblOPN.Text;
customer = lblcustomer.Text;
distymodel = lbldistymodel.Text;
try
{
DataAccess.DeleteCustBuffer(distymodel, customer, opn);
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
catch (Exception ex)
{
error = getErrorMessage(ex.Message);
ClientScript.RegisterStartupScript(this.GetType(), "ERROR:Remove", "<script>alert('" + error + "');</script>");
}
}
----------------------------------------------------------------------------------------------------------------------
<table id="tbGridView" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<div id="divGridView" style="width: 100%; overflow: auto;">
<asp:GridView ID="gvList" runat="server"
CssClass="scrolltable" SkinID="gvList"
AutoGenerateColumns="false" CellPadding="2"
OnRowEditing="gvList_RowEditing"
OnRowCancelingEdit="gvList_RowCancelingEdit"
OnRowUpdating="gvList_RowUpdating"
OnRowDeleting="gvList_RowDeleting">
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false">
<HeaderTemplate>Actions</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbtnEdit" CssClass="Text7" runat="server" CommandName="Edit" Text="Edit"/>
<span> | </span>
<asp:LinkButton ID="lbtnDelete" CssClass="Text7" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="javascript:return confirm('Are you sure you want to delete?');" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbtnUpdate" CssClass="Text7" runat="server" CommandName="Update" Text="Update"/>
<span> | </span>
<asp:LinkButton ID="lbtnCancel" CssClass="Text7" runat="server" CommandName="Cancel" Text="Cancel" OnClientClick="aspnetForm.reset()" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disty Model">
<ItemTemplate>
<asp:Label ID="lbldistymodel" Runat="server" Text='<%# Bind("Disty_Model_Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDistyModel" runat="server" ReadOnly="true" Text='<%# Bind("Disty_Model_Name") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer">
<ItemTemplate>
<asp:Label ID="lblcustomer" Runat="server" Text='<%# Eval("Customer_Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtcustomer" runat="server" ReadOnly="true" Text='<%# Bind("Customer_Name") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OPN">
<ItemTemplate>
<asp:Label ID="lblOPN" Runat="server" Text='<%# Bind("OPN") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtOPN" runat="server" ReadOnly="true" Text='<%# Bind("OPN") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Override">
<ItemTemplate>
<asp:Label ID="lblOverride" Runat="server" Text='<%# Bind("Override") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="50px" ID="txtOverride" runat="server" Text='<%# Bind("Override") %>'/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Min">
<ItemTemplate>
<asp:Label ID="lblOverrideMin" Runat="server" Text='<%# Bind("Override_Min") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="50px" ID="txtOverrideMin" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Max">
<ItemTemplate>
<asp:Label ID="lblOverrideMax" Runat="server" Text='<%# Bind("Override_Max") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="50px" ID="txtOverrideMax" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<asp:Label ID="lblComments" Runat="server" Text='<%# Bind("Comments") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="500px" ID="txtComments" runat="server" Text='<%# Eval("Comments") %>'/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</table>
I am facing a strange behavior which I am not able to find the solution.
I have a Gridview to show data from my database and after click on Edit, I will allow certain fields to be modified.
However, when I click Update, some of the fields not able to accept the new value and some field are taking new values + old values, thus making it wrong.
Let's say, my txtComments original data is empty string.
Now, I click Edit, and Update without modifying the data in txtComments, I will get ",,"
Then I click Edit again and Update without modifying the data in txtComments, I will get ",,,,,,,,"
Let's say, my txtComments original data is "123"
Now, I click Edit, and Update without replace the data in txtComments to 456, I will get 456,123,123
Other than that I am not able to read new value for txtOverrideMin, txtOverrideMin, txtOverrideMax
It is pretty strange and I try to debug it and see where the values are from, some how no avail.
Here are some of my codes, I hope you can spot where it goes wrong.
Thanks for any assistance.
protected void gvList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvList.EditIndex = -1;
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
protected void gvList_RowEditing(object sender, GridViewEditEventArgs e)
{
gvList.EditIndex = e.NewEditIndex;
PopulateFilters(this.DataContext);
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
protected void gvList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtOverride = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtOverride");
TextBox txtOverrideMin = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtOverrideMin");
TextBox txtOverrideMax = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtOverrideMax");
TextBox txtComments = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtComments");
TextBox txtDistyModel = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtDistyModel");
TextBox txtcustomer = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtcustomer");
TextBox txtOPN = (TextBox)gvList.Rows[e.RowIndex].FindControl("txtopn");
Int32.TryParse(txtOverride.Text, out Qty_override);
Int32.TryParse(txtOverrideMin.Text, out Qty_override_min);
Int32.TryParse(txtOverrideMax.Text, out Qty_override_max);
comments = txtComments.Text;
customer = txtcustomer.Text;
opn = txtOPN.Text;
distymodel = txtDistyModel.Text;
try
{
DataAccess.EditCustomerBuffer(
"Edit",
distymodel,
customer,
opn,
Qty_override,
Qty_override_min,
Qty_override_max,
comments);
gvList.EditIndex = -1;
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
catch (Exception ex)
{
error = getErrorMessage(ex.Message);
ScriptManager.RegisterClientScriptBlock(
this,
this.GetType(),
"ERROR:Edit",
"alert('" + error + "');",
true);
}
}
protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lbldistymodel = (Label)gvList.Rows[e.RowIndex].FindControl("lbldistymodel");
Label lblOPN = (Label)gvList.Rows[e.RowIndex].FindControl("lblOPN");
Label lblcustomer = (Label)gvList.Rows[e.RowIndex].FindControl("lblcustomer");
opn = lblOPN.Text;
customer = lblcustomer.Text;
distymodel = lbldistymodel.Text;
try
{
DataAccess.DeleteCustBuffer(distymodel, customer, opn);
gvList.DataSource = GetData(this.DataContext);
gvList.DataBind();
}
catch (Exception ex)
{
error = getErrorMessage(ex.Message);
ClientScript.RegisterStartupScript(this.GetType(), "ERROR:Remove", "<script>alert('" + error + "');</script>");
}
}
----------------------------------------------------------------------------------------------------------------------
<table id="tbGridView" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<div id="divGridView" style="width: 100%; overflow: auto;">
<asp:GridView ID="gvList" runat="server"
CssClass="scrolltable" SkinID="gvList"
AutoGenerateColumns="false" CellPadding="2"
OnRowEditing="gvList_RowEditing"
OnRowCancelingEdit="gvList_RowCancelingEdit"
OnRowUpdating="gvList_RowUpdating"
OnRowDeleting="gvList_RowDeleting">
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false">
<HeaderTemplate>Actions</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbtnEdit" CssClass="Text7" runat="server" CommandName="Edit" Text="Edit"/>
<span> | </span>
<asp:LinkButton ID="lbtnDelete" CssClass="Text7" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="javascript:return confirm('Are you sure you want to delete?');" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbtnUpdate" CssClass="Text7" runat="server" CommandName="Update" Text="Update"/>
<span> | </span>
<asp:LinkButton ID="lbtnCancel" CssClass="Text7" runat="server" CommandName="Cancel" Text="Cancel" OnClientClick="aspnetForm.reset()" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Disty Model">
<ItemTemplate>
<asp:Label ID="lbldistymodel" Runat="server" Text='<%# Bind("Disty_Model_Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDistyModel" runat="server" ReadOnly="true" Text='<%# Bind("Disty_Model_Name") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer">
<ItemTemplate>
<asp:Label ID="lblcustomer" Runat="server" Text='<%# Eval("Customer_Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtcustomer" runat="server" ReadOnly="true" Text='<%# Bind("Customer_Name") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OPN">
<ItemTemplate>
<asp:Label ID="lblOPN" Runat="server" Text='<%# Bind("OPN") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtOPN" runat="server" ReadOnly="true" Text='<%# Bind("OPN") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Override">
<ItemTemplate>
<asp:Label ID="lblOverride" Runat="server" Text='<%# Bind("Override") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="50px" ID="txtOverride" runat="server" Text='<%# Bind("Override") %>'/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Min">
<ItemTemplate>
<asp:Label ID="lblOverrideMin" Runat="server" Text='<%# Bind("Override_Min") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="50px" ID="txtOverrideMin" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Max">
<ItemTemplate>
<asp:Label ID="lblOverrideMax" Runat="server" Text='<%# Bind("Override_Max") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="50px" ID="txtOverrideMax" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<asp:Label ID="lblComments" Runat="server" Text='<%# Bind("Comments") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox SkinID="txt" Width="500px" ID="txtComments" runat="server" Text='<%# Eval("Comments") %>'/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</table>