如何在子网格中单击按钮时获取父网格行索引 [英] how get parent grid row index while clicking a button in Child grid
问题描述
如何在点击子网格中的按钮时获取父网格行索引。
我使用了这个链接中的代码
(嵌套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)((LinkButton) )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屋!