zoukankan      html  css  js  c++  java
  • [英语阅读笔记]Creating Master Detail Pages using GridView

    原文地址:http://www.dotnetbips.com/articles/4c3cc1c7-795e-4058-a741-e8e1de6d90a9.aspx

    作者:Bipin Joshi

    这篇文章与我之前对于Master-Detail方式的实现有所不同,而是在GridView中用GridView来显示Detail。效果如下:

    文章中的实现,首先在GridView中添加两个模板列,一个用来绑定字段显示信息用,一个用来放置按钮。这个按钮里要设置CommandName属性以配合下面的一段代码。

    这个按钮要实现的功能是在点击它的时候当前行展开并且在前面的绑定列中显示一个GridView来显示关联信息。

    然后编辑第一个模板列,除了添加两个Label显示信息外,另加一个SqlDatasource和GridView.

    实现的关键点是让里面的这个SqlDatasource接收到外面这个GridView行里传递过来的参数,依靠以下的两个代码片断:

    private int index = 0;

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    Button b = (Button)e.Row.Cells[1].FindControl("Button1");

    b.CommandArgument = index.ToString();

     index=index+1;

    }

    }

    这个代码是在外面的GridView中行被绑定的时候触发的,还有一个代码:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

    {

    if (e.CommandName == "Show")

    {

    Button b = (Button)GridView1.Rows[int.Parse (e.CommandArgument.ToString())].Cells[1]. FindControl("Button1");

    if (b.Text == "Show")

    {

    string custid = GridView1.DataKeys[int.Parse (e.CommandArgument.ToString())].Value.ToString();

    SqlDataSource sds = (SqlDataSource)GridView1. Rows[int.Parse(e.CommandArgument.ToString())]. FindControl("SqlDataSource2");

    GridView gv = (GridView)GridView1.Rows[int.Parse (e.CommandArgument.ToString())].FindControl("GridView2");

    sds.SelectParameters[0].DefaultValue = custid;

    gv.Visible = true; b.Text = "Hide";

    }

    else

    {

    GridView gv = (GridView)GridView1.Rows[int.Parse (e.CommandArgument.ToString())].FindControl("GridView2");

    gv.Visible = false;

    b.Text = "Show";

    }

    }

    }

    很佩服老外的想象力,看他们的一些问题的实现总能悟到很多东西。

    ---------------------------------------------------------------

    aspnetxBI笔记系列索引:

    使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能

    一起玩转SQL Server 2012 下的分析服务

    使用SQL Server分析服务定位目标用户

    ---------------------------------------------------------------

    来自博客园aspnetx宋卫东

  • 相关阅读:
    0421 & SX2016
    HDU3948 & 回文树模板
    BZOJ 2152 & 点分治
    HDU5618 & CDQ分治
    CC countari & 分块+FFT
    ECF R9(632E) & FFT
    ECF R9(632E) & DP
    BZOJ的两道osu概率DP easy与osu
    BZOJ3197 & 组合乱搞
    转载 Rational Rose 的配置和破解
  • 原文地址:https://www.cnblogs.com/aspnetx/p/798112.html
Copyright © 2011-2022 走看看