为什么我必须在删除,更新,取消事件时绑定Gridview [英] Why I Must Bind Gridview On Delete,Update,Cancel Events

查看:82
本文介绍了为什么我必须在删除,更新,取消事件时绑定Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  GridView1_RowEditing(对象发​​件人,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}



我需要上面代码的解释

我知道e.neweditindex使我能够选择行可编辑。

但我的询问是上面的代码在我写下面的方法之前没有正常工作

 GetDataFromCache(); 



将数据源分配给Grid并绑定它,...............为什么我需要绑定它再次,因为它已经绑定之前。

解决方案

此代码可帮助您获取在gridview中单击的相应行,并允许您编辑和更新您的内容gridview中的那一特定行。


每当你的页面回发数据丢失,因为http是无状态协议。要在网格中维护数据,您可以每次调用ur函数,也可以在Viewstate中维护数据。如果你在函数中从后端获取数据并且每次调用该函数它会增加服务器上的负载而不是你应该使用viewstate





GridView1.EditIndex = e.NewEditIndex;

Datatable dt = ViewState [data] as Datatable;

Gridview1.DataSource = dt;

GridView1.DataBind();

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
        }


hi , i need an explanation for above code
I know that e.neweditindex enables me to make the selected row editable .
but my inquiry is that above code not working correctly until i write the below method

GetDataFromCache();


which assign datasource to Grid and also bind it ,............... why i need to bind it again as it was already binded before.

解决方案

This code helps you to get the respective row on which you clicked in the gridview & enables you to edit & update your content of that particular row in the gridview.


whenever your page post back data is lost because http is Stateless protocol. To maintain data in grid either you call ur function every time or u can maintain data in Viewstate. if u r fetching data from backend in function and call that function everytimr it increase load on your server instead of that you should use viewstate


GridView1.EditIndex = e.NewEditIndex;
Datatable dt=ViewState["data"] as Datatable;
Gridview1.DataSource=dt;
GridView1.DataBind();


这篇关于为什么我必须在删除,更新,取消事件时绑定Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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