Gridview RowCommand事件 [英] Gridview RowCommand event

查看:77
本文介绍了Gridview RowCommand事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中添加了选择命令按钮.在RowCommand事件上,我将代码编写为

I have added select command button in gridview. and on RowCommand event I have written code as

gvCloserComments.EnableViewState = true;
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gr = gvCloserComments.Rows[index];
lblCCID.Text = gr.Cells[0].Text;
txtCloserComments.Text = gr.Cells[1].Text;



但是,当我单击选择链接gridview时,它被清除,并且显示错误为



But when I clicked on select link gridview getting cleared and it showing error as

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index



所以我的问题是为什么在rowcommand上清除gridview.



So my question is why gridview getting cleared on rowcommand.

推荐答案

我假设您正在尝试使用当前行,

I assume you are trying to get the current row using,

int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gr = gvCloserComments.Rows[index];



如果使用RowCommand事件,则应该可以使用e.Row获取当前行.

请检查您是否有两列(2个单元格),因为以下代码可能会出现问题.



If you are using RowCommand event, you should able to get the current row using e.Row.

Please check you have two columns (2 cells) as the problem could on the below codes.

lblCCID.Text = gr.Cells[0].Text;
txtCloserComments.Text = gr.Cells[1].Text;


这篇关于Gridview RowCommand事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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