单击gridview中的复选框时如何防止回发 [英] How to prevent postback when checkbox in gridview is clicked

查看:79
本文介绍了单击gridview中的复选框时如何防止回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击gridview中的复选框时如何防止回发



i有gridview如下,带复选框





复选框滑动日期滑动无季节DistributionType区域区域



复选框28-03-2018 23 2018 Agri IVC Volko

复选框20-04-2018 24 2019 Agri IVC Zolko

复选框21-06-2018 25 2018 Agri IVC Molko

复选框18-03-2018 15 2019 Agri IVC Rolko

复选框10-03-2018 22 2018 Agri IVC Solko



例如我点击gridview中的复选框第5行意味着,它不会停留在gridview中点击选中的行,它会回发并显示gridview的顶部。





如何预防单击gridview中的复选框时回发。



如何解决此问题



我尝试了什么:



如果在点击gridview中的复选框时如何防止回发



i有gridview如下带复选框





复选框滑动日期滑动无季节DistributionType Region Zone



复选框28-03-2018 23 2018 Agri IVC Volko

复选框20-04-2018 24 2019 Agri IVC Zolko

复选框21-06-2018 25 2018 Agri IVC Molko

复选框18-03-2018 15 2019 Agri IVC Rolko

复选框10-03- 2018 22 2018 Agri IVC Solko



例如我点击gridview第5行的复选框意味着,它不会停留在gridview中点击选中的行,它会回发并显示gridview的顶部。





当gridview中的复选框为cl时,如何防止回发icked



如何解决这个问题

how to prevent postback when checkbox in gridview is clicked

i have gridview as follows with checkbox


Checkbox Slip Date Slip No Season DistributionType Region Zone

Checkbox 28-03-2018 23 2018 Agri IVC Volko
Checkbox 20-04-2018 24 2019 Agri IVC Zolko
Checkbox 21-06-2018 25 2018 Agri IVC Molko
Checkbox 18-03-2018 15 2019 Agri IVC Rolko
Checkbox 10-03-2018 22 2018 Agri IVC Solko

for example i am click the checkbox in the gridview 5th row means,it will not stay in clicking selected row in gridview, it will postback and shows the top of the gridview.


how to prevent postback when checkbox in gridview is clicked.

how to solve this issue

What I have tried:

how to prevent postback when checkbox in gridview is clicked

i have gridview as follows with checkbox


Checkbox Slip Date Slip No Season DistributionType Region Zone

Checkbox 28-03-2018 23 2018 Agri IVC Volko
Checkbox 20-04-2018 24 2019 Agri IVC Zolko
Checkbox 21-06-2018 25 2018 Agri IVC Molko
Checkbox 18-03-2018 15 2019 Agri IVC Rolko
Checkbox 10-03-2018 22 2018 Agri IVC Solko

for example i am click the checkbox in the gridview 5th row means,it will not stay in clicking selected row in gridview, it will postback and shows the top of the gridview.


how to prevent post back when checkbox in gridview is clicked

how to solve this issue

推荐答案

既然你的GridView和CheckBox是服务器控件,当你触发CheckChanged事件,会引发回发。当它回发并且你进行了数据绑定时,它将重置CheckBox的状态并返回默认状态的GridView。



请记住,网络应用程序是无状态,你必须做一些事情来坚持驻留在网格中的复选框的状态。您必须跟踪所选复选框并将其存储在某处(例如ViewState / Session),以便在回发时可以引用它们。看一下这篇文章:九个用于管理持久用户状态的选项ASP.NET应用程序。您也可以参考此示例以在分页网格上保留复选框状态:在ASP.Net GridView控件中分页时保留复选框的状态



如果你真的想避免回发,那么你的UpdatePanel赢了没有帮助。您需要使用客户端GridView并使用JavaScript / jQuery在客户端操作所有内容。
Since your GridView and CheckBox are server controls, when you trigger CheckChanged event, it will cause a postback. When it postbacks and you did a Data bind, it will reset the state of your CheckBox and return the GridView of the default state.

Keep in mind that web apps are stateless and you have to do something to persist the state of the checkbox that resides in grid. You'll have to track the selected checkbox and store it somewhere (like ViewState/Session for example) so that you can reference them back when it postbacks. Take a look at this article: Nine Options for Managing Persistent User State in Your ASP.NET Application. You may also refer this example for persisting checkbox state on paged grid: Preserving state of Checkboxes while paging in ASP.Net GridView Control

If you really want to avoid postbacks, then your UpdatePanel won't help. You would need to use a client-side GridView and manipulate everything at the client-side using JavaScript/jQuery.


这篇关于单击gridview中的复选框时如何防止回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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