gridview1_Rowupdating不提供新的更新值. [英] gridview1_Rowupdating not giving new updated value.

查看:191
本文介绍了gridview1_Rowupdating不提供新的更新值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在尝试在页面中构建一个gridview,直到我编辑一条记录并按Update时,一切都可以正常工作.当我这样做时,它将使用旧值.
我在更新事件中的代码是

我的后台代码是:

Hi all
I am trying to build a gridview in a page, everything is working properly until I edit a record and press Update, when I do, it takes the old values.
my code in the updating event is

My code-behind is:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gridviewbind();

        }





protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow gr = GridView1.Rows[e.RowIndex];

        TextBox txt = (TextBox)gr.FindControl("txtname");
        cs.Name = txt.ToString();
        cs.Updaterecord();
        gridviewbind();
        GridView1.EditIndex = -1;
       
    }



这里的cs是类文件的对象,而Name是我在类文件中定义的属性.
当我通过在文件中放置断点进行检查时,它将显示gr和cs.name的空值.

请帮我..
在此先感谢...



here cs is object of class file and Name is property that i define in class file.
when i check by putting breakpoint in file than it shows null value for gr and cs.name..

plz help me..
thanks in advance...

推荐答案



我认为问题出在您的"gridviewbind" 函数中.您只需检查一次即可..如果数据正在数据库中更新,而未在gridview中更新,则意味着更新数据后,您没有将网格正确地绑定到数据源..
--AK
Hi,

As I think, problem is in your "gridviewbind" function. You just check it once.. If the data is updating in database and not updating in gridview means after updating the data you are not binding the grid to datasource currectly..
--AK


尝试以下代码.
try the following code.
        GridViewRow gr = (GridViewRow)GridView1.Rows[e.RowIndex];
        TextBox txt = (TextBox)gr.FindControl("txtname");
        GridView1.EditIndex = -1 ;

         cs.Name = txt.Text;
         
        cs.Updaterecord();
        gridviewbind();

hope that help you. or please check your Update Query or post your Query.


这篇关于gridview1_Rowupdating不提供新的更新值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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