如何在更新c#asp.net中的值之前将gridview textbox oldvalue与newvalue进行比较? [英] How to compare gridview textbox oldvalue to newvalue before updating values in c# asp.net?
本文介绍了如何在更新c#asp.net中的值之前将gridview textbox oldvalue与newvalue进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
如何在更新c#asp.net中的值之前将gridview textbox oldvalue与newvalue进行比较?
我正在使用此用于更新gridview值的代码。
Hello,
How to compare gridview textbox oldvalue to newvalue before updating values in c# asp.net?
I am using this code for updating value of gridview.
protected void GVStartCampaignDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtAmountValue = (TextBox)GVStartCampaignDetails.Rows[e.RowIndex].FindControl("txtGVSCAmountValue");
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmdUpdateAllowtedCardNo = new SqlCommand("procUpdateAmount", con);
cmdUpdateAllowtedCardNo.CommandType = CommandType.StoredProcedure;
cmdUpdateAllowtedCardNo.Parameters.Add("@EmailId", SqlDbType.NVarChar).Value = EmailId;
cmdUpdateAllowtedCardNo.Parameters.Add("@Amount", SqlDbType.Int).Value = Convert.ToInt32(txtAmountValue.Text);
cmdUpdateAllowtedCardNo.ExecuteNonQuery();
con.Close();</pre>
GVStartCampaignDetails.EditIndex = -1;
}
如何在更新程序之前将txtAmountValue OldValue与NewValue进行比较?
请帮帮我。
在此先感谢。
Ankit Agarwal
网站开发者
how to compare txtAmountValue OldValue to NewValue before update procedure?
Please help me.
Thanks in Advance.
Ankit Agarwal
Website Developer
推荐答案
你必须使用 GridViewUpdatedEventArgs.OldValues属性 [ ^ ]。
You have to use GridViewUpdatedEventArgs.OldValues Property[^].
Quote:
获取一个字典,其中包含更新记录的原始字段名称/值对。
Gets a dictionary that contains the original field name/value pairs for the updated record.
这样做,
使用隐藏字段
添加模板字段
并绑定金额
价值。
每当您更新特定的行
时,
,您可以从该行的隐藏字段中读取旧值。和
文本框中的新值
,
然后你可以比较
两者。
如果两者都是不同
你可以更新
数据否则忽略它......
示例代码:
Do like this,
Add atemplate field
with ahidden field
and bind theamount
value to it.
whenever you are updating the particularrow
, you can read theold value from that row's hidden field
. andnew value from the text box
,
then you cancompare
the both.
if both aredifferent
you canupdate
the data else ignore it...
sample code:
TextBox txtAmountValue = (TextBox)GVStartCampaignDetails.Rows[e.RowIndex].FindControl("txtGVSCAmountValue");
HiddenField hdfldGVSCAmountValue = (HiddenField)GVStartCampaignDetails.Rows[e.RowIndex].FindControl("hdfldGVSCAmountValue");
double oldvalue, newvalue;
double.TryParse(txtAmountValue.Text, out newvalue);
double.TryParse(hdfldGVSCAmountValue.Value, out oldvalue);
if (newvalue >= oldvalue) // your custom conditions here
{
// do something
}
这篇关于如何在更新c#asp.net中的值之前将gridview textbox oldvalue与newvalue进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文