在RowCommand事件中获取索引值示例代码
投稿:whsnow
这篇文章主要介绍了如何在RowCommand事件中获取索引值,需要的朋友可以参考下
在RowCommand事件中获取索引值 
1.利用e.CommandSource
 
protected void lpg_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ItemCollect")
{
GridViewRow gvr = (GridViewRow)(((LinkButton)(e.CommandSource)).NamingContainer);
LinkButton lk = lpgKnowledgeExchange.Rows[gvr.RowIndex].FindControl("lbtnCollect") as LinkButton;
}
}
 
2.如果是模板列中的button直接click事件
利用sender 取其parent 也可以实现
 
1.利用e.CommandSource
复制代码 代码如下:
protected void lpg_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ItemCollect")
{
GridViewRow gvr = (GridViewRow)(((LinkButton)(e.CommandSource)).NamingContainer);
LinkButton lk = lpgKnowledgeExchange.Rows[gvr.RowIndex].FindControl("lbtnCollect") as LinkButton;
}
}
2.如果是模板列中的button直接click事件
利用sender 取其parent 也可以实现
您可能感兴趣的文章:
- 用Command对象和RecordSet对象向数据库增加记录哪一个更好
 - 使用Jmail及Winwebmail发信时系统记录中的错误:502 Error: command ...
 - Delphi Command模式
 - asp中command的在单条记录时,有些字段显示为空的问题
 - javascript document.execCommand() 常用解析
 - asp.net gridview的Rowcommand命令中获取行索引的方法总结
 - php设计模式 Command(命令模式)
 - php设计模式 Command(命令模式)
 - 获取Repeter的Item和ItemIndex/CommandArgument实现思路与代码
 - 解决VS2012 Express的There was a problem sending the command to the program问题
 - bash scp command not found的解决方法
 - GridView中动态设置CommandField是否可用或可见的小例子
 - document.execCommand()的用法小结
 - pip 错误unused-command-line-argument-hard-error-in-future解决办法
 - ON_COMMAND_RANGE多个按钮响应一个函数的解决方法
 - C#命令模式(Command Pattern)实例教程
 - ASP基础知识Command对象讲解
 
