Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB Grid - input Text Box not capturing user input value

Status
Not open for further replies.

davidku

Programmer
Aug 6, 2002
24
MY
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>
 
this code looks clean. the problem is either UpdateCustBuffer() or GetData(). can you post the code for these methods?

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
The issue is when I am in this event - gvList_RowUpdating , I read the "wrong" value in debug mode.

Here's the function for

public static void EditCustomerBuffer(
string action,
string distymodelname,
string customer,
string opn,
int qty_override,
int qty_override_min,
int qty_override_max,
string comments
)
{
using (OracleConnection conn = DataAccess.GetConnection())
{
conn.Open();

using (OracleCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_EDIT_CUSTBUF";

cmd.Parameters.Add(
"v_Action",
OracleType.VarChar)
.Value = action;

cmd.Parameters.Add(
"v_Disty_Model",
OracleType.VarChar)
.Value = distymodelname;

cmd.Parameters.Add(
"v_Customer",
OracleType.VarChar)
.Value = customer;

cmd.Parameters.Add(
"v_OPN",
OracleType.VarChar)
.Value = opn;

cmd.Parameters.Add(
"v_Override",
OracleType.Number)
.Value = qty_override;

cmd.Parameters.Add(
"v_Override_Min",
OracleType.Number)
.Value = qty_override_min;

cmd.Parameters.Add(
"v_Override_Max",
OracleType.Number)
.Value = qty_override_max;

cmd.Parameters.Add(
"v_Comments",
OracleType.VarChar)
.Value = comments;

cmd.ExecuteNonQuery();
}
}
}

---------------------------------------------------------

protected override DataTable GetData(PageDataContext ctx)
{
string distyModel = String.Empty;
string opn = String.Empty;
string customer = String.Empty;

FilterCriteria fc = null;

if ((fc = ctx.GetFilter("DistyModel")) != null)
{
distyModel = fc.Value;
}

if ((fc = ctx.GetFilter("OPN")) != null)
{
opn = fc.Value;
}

if ((fc = ctx.GetFilter("Customer")) != null)
{
customer = fc.Value;
}

DataTable dt = DataAccess.GetCustomerBuffer(
distyModel,
opn,
customer);

return dt;
}

---------------------------------------------------------

public static DataTable GetCustomerBuffer(
string distyModel,
string opn,
string customer )
{
DataTable dt = null;

using (OracleConnection conn = DataAccess.GetConnection())
{
conn.Open();

using (OracleCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "WEBDATA_pkg.sp_GET_CUST_BUF_Qry";

cmd.Parameters.Add(
"v_Disty_Model",
OracleType.VarChar).Value =
ToDBValue<string>(distyModel, String.Empty);

cmd.Parameters.Add(
"v_OPN",
OracleType.VarChar).Value =
ToDBValue<string>(opn, String.Empty);

cmd.Parameters.Add(
"v_Customer",
OracleType.VarChar).Value =
ToDBValue<string>(customer, String.Empty);

cmd.Parameters.Add(
"v_Return_Cursor",
OracleType.Cursor)
.Direction = ParameterDirection.Output;

using (OracleDataAdapter da = new OracleDataAdapter(cmd))
{
dt = new DataTable();

dt.BeginInit();
dt.BeginLoadData();

da.Fill(dt);

dt.EndLoadData();
dt.EndInit();
}
}
}
return dt;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top