Create a pop-up Details window in DataGrid

xiaoxiao2021-03-06  85

Create a pop-up Details window in DataGrid

This article comes from DOTNETJUNKIE proposal. 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.ispostback)

THIS.BINDDATA ();

}

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 (System.String Connectionstring)

{

SqlConnection C = New SqlConnection (Connectionstring);

C.Open ();

Return C;

}

#ndregion

#Region Web Form Designer Generated Code

Override protected void oninit (Eventargs E)

{

InitializationComponent (); Base.onit (E);

}

Private vidinitiRizeComponent ()

{

This.Load = New System.EventHandler (this.page_load);

}

#ndregion

}

}

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