(嵌套gridview):如何在子gridview链接按钮上单击获取父gridview rowindex [英] (nested gridview):How to Get parent gridview rowindex on a child gridview link button click

查看:142
本文介绍了(嵌套gridview):如何在子gridview链接按钮上单击获取父gridview rowindex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好专家,

我在gridview中有一个gridview。意味着我有一个主视图,里面有子gridview。现在我在子gridview中有一个链接按钮。我的问题是当我点击子网格视图的链接按钮时我如何找到主gridview行索引。



谢谢

Hello experts,
I have a gridview inside a gridview. means I have a master view which have child gridview inside. Now i have a link button in child gridview. my problem is how i find master gridview row index when i click link button of child grid view.

Thanks

推荐答案

我找到了解决方案.........

I have find solution.........
GridViewRow Gv2Row = (GridViewRow)((LinkButton)sender).NamingContainer;       
        GridView Childgrid = (GridView)(Gv2Row.Parent.Parent);       
        GridViewRow Gv1Row = (GridViewRow)(Childgrid.NamingContainer);
        int b = Gv1Row.RowIndex;


为您的孩子添加以下代码 GridView

add below code for your child GridView.
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "go")
        
          {

        GridViewRow Gv2Row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
        GridView Childgrid = (GridView)(Gv2Row.Parent.Parent);
       
        GridViewRow Gv1Row = (GridViewRow)(Childgrid.NamingContainer);
        GridView Parentgrid = (GridView)(Gv1Row.Parent.Parent);
        
       foreach (GridViewRow Grid1row in Parentgrid.Rows)
        {
            Label lbl = (Label)(Grid1row.FindControl("Label1"));
            string grid2Rowtext = lbl.Text;
            Response.Write(grid2Rowtext + "<br>");

        }
    }
}


这篇关于(嵌套gridview):如何在子gridview链接按钮上单击获取父gridview rowindex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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