如何在gridview标题上单击按钮获取网格视图的记录 [英] How to get records of grid view on click of button on header of gridview

查看:95
本文介绍了如何在gridview标题上单击按钮获取网格视图的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用网格视图,显示登录用户的所有任务。用户可以检查/取消选中任务,并根据复选框状态,在网格视图上更新记录。

我的网格视图具有模板字段,其中包含标题模板和项目模板。标题模板包含复选框,asp:按钮和项模板包含复选框。选中/取消选中标题模板复选框时,将检查/取消选中项目模板中的所有复选框。 asp:按钮的目的是根据行的检查/未检查状态更新数据库上的记录。



我想要的是点击标题模板上的asp:按钮,将获取网格视图的所有记录,包括选中状态的复选框,以便检查状态可以在数据库上更新。



我曾使用过网格视图的行命令事件。它点击按钮就触发了处理程序。但是,我无法获得记录。

用于完成此操作的事件是什么?我怎样才能做到这一点。



http://stackoverflow.com/questions/28870200/how-to-get-records-of-grid-view-on-click-of-button-on- header-of-gridview [ ^ ]

I am using grid view that shows all the tasks for log in user. User can check/unchecked tasks and based on check box status, record is updated on grid view.
My grid view has template field which has header template and item template. Header template contains check boxes and asp:button and item template contains check boxes. On check/unchecked of header template check boxes, all check boxes in item template are checked/unchecked. The purpose of asp:button is to update records on database based on check/unchecked status of rows.

What i wanted is on click of asp:button on header template, all records of grid view are to be fetched including check boxes checked status so that the check status can be updated on database.

I had used row command event of grid view. It fired on handler on click of button. However, I am not able to get records.
Which event is used to accomplish this? How can i do this.

http://stackoverflow.com/questions/28870200/how-to-get-records-of-grid-view-on-click-of-button-on-header-of-gridview[^]

推荐答案

内部 RowCommand 您可以轻松获得该特定行。正如您所说,您希望获取所有行,然后在该事件中,您只需要遍历所有 GridViewRow



在循环中,你可以得到行的所有细节,包括复选框检查状态。
Inside RowCommand you can easily get that particular Row. As you are saying that you want all the rows to be fetched, then inside that event you just need to loop through all the GridViewRow.

Inside the loop, you can get all the details of the rows including the checkbox check status.


谢谢Tadit,我这样做了:



thanks Tadit, I did like this:

protected void gridTransaction_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "headerClicked")
            {
                foreach (GridViewRow row in gridTransaction.Rows)
                {
                    var record = row;
                }
            }
        }





我做了一些调试,在记录中,dataItem显示为null 。文字也是空白的。我在页面加载时绑定网格..我错过了导致null项目被绑定的东西???



I did some debugging, in record, dataItem shown is null. Also text is blank. I am binding grid on page load..Did i missed something that resulted to null item being binded???


我使用jquery获取gridview的所有元素列表,然后我去了服务器端并执行保存操作。
I used jquery to get all elements of gridview in list, then i went to serverside and did operation of saving.


这篇关于如何在gridview标题上单击按钮获取网格视图的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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