简体   繁体   中英

(ASP.NET) How to do this: Button click in GridView to open pop-up window containing another Gridview

As from the title, I would like to do a pop-up window on click of a ItemTemplate button in a GridView(1).

The pop-up window will contain another GridView(2), and this one contains information(retrieved from database), this information is the same as GridView(1) and I only want the data from the row index of the Button.

These are some code that I have. 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) design:

 <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 file codes:

 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); } 

The above codes that I have don't work and I can't seem to find the problem with it, or I may have forgot something. In case you are wondering which part, the new window does not pop-up. Thank you.

1) You can put Hyperlink Button in Gridview and Provide path for second Gridview. You can follow this link also. Open new gridview through Hyperlink And Make a Connection Class for that. 2) Make a Gridview on one aspx page. And make another Gridview on another page. Response.Redirect("~/secondGridviewpageYouwantTocall.aspx"); you can use this to redirect

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM