如何在更新c#asp.net中的值之前将gridview textbox oldvalue与newvalue进行比较? [英] How to compare gridview textbox oldvalue to newvalue before updating values in c# asp.net?

查看:62
本文介绍了如何在更新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 a template field with a hidden field and bind the amount value to it.
whenever you are updating the particular row, you can read the old value from that row's hidden field. and new value from the text box ,
then you can compare the both.
if both are different you can update 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆