Create a pop-up Details window in DataGrid

zhaozj2021-02-17  51

By: DONNY MACKLEVEL: IntermediatePosted Date:

1/2/2002

Tested with asp.net beta 2 (v.1.0.2914.16) Click Here to Download Sample CODE

Create a pop-up Details window in DataGrid This article comes from DotNetJunkie. He originally writes the letter to provide an example of how to create HyperLinkColumn in DataGrid, you can open a new window after the user clicks this column, showing the details of this column. We have answered them through Email, he suggested that we have added this method to their guidelines, so there is this article. Like our original article, it is very simple, but simple-containing method examples can sense developers more effectively. This example contains two WebForms and a CSS file (all code can be downloaded) - the first WebForm contains a DataGrid of the product list read from the Northwind library, and HyperLink's State is set to "SEEDETAILS", once this The link is clicked, and the JavaScript clip will call. The user wants to get the product's ProductID as a parameter in the URL. The second WebForms containing another DataGrid lists all the specific users of the product. detail. Let's take a look at WebForm1.asp and WebFiorm1.aspx.cs.

Webform1.aspx <% @ page language = "c #" autoeventwireup = "false" inherits = "Howtos.DataGrid.popupwindow.Webform1"%>

Webform1.aspx.cs using system;

using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web .UI.WebControls; using System.Web.UI.HtmlControls; namespace HowTos.DataGrid.PopupWindow {public class WebForm1: System.Web.UI.Page {protected System.Web.UI.WebControls.DataGrid DataGrid1; #region User Defined Code private void Page_Load (object sender, System.EventArgs e) {if this.BindData () (this.IsPostBack!);} protected void BindData () {SqlCommand cmd = new SqlCommand ( "SELECT TOP 10 ProductID, ProductName FROM Products", con ( "Server = LocalHost; DataBase = Northwind; TRUSTED_CONNECTION = TRUE")); this.DataGrid1.DataSource = cmd.ExecuteReader (CommandBehavior.CloseConnection); this.DataGrid1.DataBind ();} protected SqlConnection con (Sy stem.String ConnectionString) {SqlConnection c = new SqlConnection (ConnectionString); c.Open (); return c;} #endregion #region Web Form Designer generated code override protected void OnInit (EventArgs e) {InitializeComponent (); base.OnInit (e);} private void initializecomponent () {this.load = new system.eventhandler (this.page_load);} #ENDREGON}}

In addition to DataNavigateURLFORMATSTRING, there is no difficulty, you can notice that I actually use a JavaScript clip (Note: You can also create a .js file or use