【问题标题】:(ASP.NET) How to do this: Button click in GridView to open pop-up window containing another Gridview(ASP.NET) 如何做到这一点:在 GridView 中单击按钮以打开包含另一个 Gridview 的弹出窗口
【发布时间】:2017-01-25 05:43:22
【问题描述】:

从标题开始,我想在单击 GridView(1) 中的 ItemTemplate 按钮时弹出一个窗口。

弹出窗口将包含另一个GridView(2),这个包含信息(从数据库中检索),该信息与GridView(1)相同,我只想要Button的行索引中的数据.

这些是我拥有的一些代码。 JavaScript:

<script type="text/javascript">
  $(function() {
    $("[id*=btnShowPopup]").click(function() {
      ShowPopup();
      return false;
    });
  });

  function ShowPopup() {
    $("#dialog").dialog({
      title: "GridView",
      width: 450,
      buttons: {
        Ok: function() {
          $(this).dialog('close');
        }
      },
      modal: true
    });
  }
</script>

GridView(2) 设计:

<div id="dialog" style="display: none">>
  <asp:GridView ID="gridviewpopup" runat="server" AutoGenerateColumns="false">
    <Columns>
      <asp:ImageField DataImageUrlField="companyLogo" HeaderText="Company Logo" ControlStyleWidth="170" ControlStyle-Height="120" />
      <asp:BoundField DataField="companyName" HeaderText="Company Name" />
      <asp:BoundField DataField="companyInfo1" HeaderText="Background Information" />
    </Columns>
  </asp:GridView>
</div>

aspx.cs 文件代码:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)

        {
            this.BindGrid();
        }
    }

private void BindGrid()

    {
        string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM companyList WHERE companyIndID ='" + Convert.ToString(ddlIndustry.SelectedValue) + "' AND companySectID='" + Convert.ToString(ddlSector.SelectedValue) + "'" ))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;

                    using (DataTable dt = new DataTable())
                    {
                        sda.Fill(dt);
                        gridviewpopup.DataSource = dt;
                        gridviewpopup.DataBind();

                    }

                }

            }

        }

    }

protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        gridviewpopup.PageIndex = e.NewPageIndex;
        this.BindGrid();
        ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);

    }

上面的代码我没有工作,我似乎找不到它的问题,或者我可能忘记了什么。 如果您想知道哪个部分,新窗口不会弹出。 谢谢。

【问题讨论】:

  • 您需要updatepanel 才能持有GridView。然后单击按钮,打开弹出窗口并通过 updatepanel refresh 刷新 GridView

标签: c# asp.net


【解决方案1】:

1) 您可以在 Gridview 中放置超链接按钮并为第二个 Gridview 提供路径。 您也可以点击此链接。 Open new gridview through Hyperlink 并为此创建一个连接类。 2) 在一个 aspx 页面上创建一个 Gridview。并在另一个页面上制作另一个 Gridview。 Response.Redirect("~/secondGridviewpageYouwantTocall.aspx"); 你可以用它来重定向

【讨论】:

    【解决方案2】:

    感谢您的回答,我无法完全按照我的意愿进行操作,但我使用 Button sender 和 GridViewRow 来获取行索引数据并使用 DataBind 将其插入到另一个 GridView 并结束该方法,而不是弹出窗口Visible = true,仍然不介意更好的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多