如何在子网格中单击按钮时获取父网格行索引 [英] how get parent grid row index while clicking a button in Child grid

查看:106
本文介绍了如何在子网格中单击按钮时获取父网格行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在点击子网格中的按钮时获取父网格行索引。



我使用了这个链接中的代码

(嵌套gridview):如何在子gridview链接按钮上获取父gridview rowindex按钮单击 [ ^ ]



但它不是工作。显示投射类型错误。



帮助我..





谢谢提前...



Vineetha ..

解决方案

这里gvInner是内部(子)gridview 。 gvInner包含一个名为Edit的链接按钮,其命令名设置为Edit。







 protected void gvInner_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName ==Edit)
{
GridViewRow inner =(GridViewRow)((LinkBut​​ton) )e.CommandSource).NamingContainer;
GridView child =(GridView)inner.Parent.Parent; //这将返回子gridview
GridViewRow parent =(GridViewRow)child.NamingContainer; //这将返回父gridview的行。
int row = parent.RowIndex; //这会返回父网格视图的行索引
}
}











 int rindex =(((GridViewRow)(((控制)(发送者))。Parent.BindingContainer)))。RowIndex ; 





在此发送方返回内部(子),Parent属性返回外部(父)gridview的DataControlFieldCell,BindingContainer返回父视图的GridviewRow





希望这能解决您的问题! :)


hi,

how get parent grid row index while clicking a button in Child grid.

I used code from this link
(nested gridview):How to Get parent gridview rowindex on a child gridview link button click[^]

but it's not working. showing casting type error.

help me ..


Thanks in advance...

Vineetha..

解决方案

Here gvInner is the inner(child) gridview. The gvInner contains a linkbutton named Edit whose commandname is set to Edit.



protected void gvInner_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                GridViewRow inner = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
                GridView child = (GridView)inner.Parent.Parent;//This returns the child gridview
                GridViewRow parent = (GridViewRow)child.NamingContainer;// this returns the row of parent gridview.
                int row = parent.RowIndex; // this returns the row index of parent gridview
            }
        }




OR

int rindex = (((GridViewRow)(((Control)(sender)).Parent.BindingContainer))).RowIndex;



In this sender returns the inner(child) and the Parent property returns the DataControlFieldCell of outer(parent) gridview and BindingContainer returns the GridviewRow of Parent gridview


Hope this solves your problem!! :)


这篇关于如何在子网格中单击按钮时获取父网格行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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