站长资源网络编程
在RowCommand事件中获取索引值示例代码
简介在RowCommand事件中获取索引值 1.利用e.CommandSource 复制代码 代码如下: protected void lpg_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "It
在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 也可以实现
上一篇:.net 数据表格显示控件介绍
下一篇:如何禁止文本框的记忆功能方法集锦