(Note) The following code is the page code because of the data, such as (<% # DataBinder.eval
(Container.DataItem, "categoryName")%>) So before using it, you must first import namespace <% @ Import namespace = "system.data"%>
Rear Code Part: First Import Name Space: Using System.Data.SqlclClient and Using System.Windows.Forms; The remaining system The default import is below the connection library code:
<%
@ Import Namespace
=
"
System.data
"
%>
<%
@ Page Language
=
"
C #
"
Codebehind
=
"
Webform1.aspx.cs
"
Autoeventwireup
=
"
False
"
Inherits
=
"
TEST1.WEBFORM1
"
%>
DOCTYPE HTML PUBLIC
"
- // W3C // DTD HTML 4.0 Transitional // EN
"
>
<
HTML
>
<
HEAD
>
<
Title
>
Webform1
Title
>
<
Meta Content
=
"
True
"
Name
=
"
VS_SNAPTOGRID
"
>
<
Meta Content
=
"
True
"
Name
=
"
VS_SHOWGRID
"
>
<
Meta Content
=
"
Microsoft Visual Studio .NET 7.1
"
Name
=
"
Generator
"
>
<
Meta Content
=
"
C #
"
Name
=
"
Code_Language
"
>
<
Meta Content
=
"
JavaScript
"
Name
=
"
VS_DEFAULTCLIENTScript
"
>
<
Meta Content
=
"
http://schemas.microsoft.com/intellisense/ie5
"
Name
=
"
vs_targetschema
"
>
HEAD
>
<
Body ms_positioning
=
"
Gridlayout
"
>
<
Form ID
=
"
Form1
"
Method
=
"
POST
"
Runat
=
"
Server
"
>
<
Font Face
=
"
Song body
"
>
<
ASP: Button ID
=
"
Button1
"
Style
=
"
Z-Index: 102; Left: 472px; Position: absolute; top: 472px
Runat
=
"
Server
"
Width
=
"
96px
"
HEIGHT
=
"
32px
"
TEXT
=
"
Button
"
>
ASP: Button
>
Font
> <
ASP: REPEATER ID
=
"
REPEATER1
"
Runat
=
"
Server
"
>
<
Headertemplate
>
<
Table Border
=
"
0
"
>
<
Tr BGColor
=
"
# 999999
"
>
<
TD
>
Product Type ID
TD
>
<
TD
>
Product Type Name
TD
>
<
TD
>
Product Type Description
TD
>
<
TD
> &
NBSP;
TD
>
TR
>
Headertemplate
>
<
ItemTemplate
>
<
Tr BGColor
=
"
#ffffffff
"
>
<
TD
>
<
IMG SRC
=
"
.iamgesattachtb.gif
"
>
<%
# DataBinder.eval (container.dataitem,
"
CategoryID
"
)
%>
TD
>
<
TD
>
<%
# DataBinder.eval (container.dataitem,
"
CategoryName
"
)
%>
TD
>
<
TD
>
<%
# DataBinder.eval (container.dataitem,
"
Description
"
)
%>
TD
>
<
TD
>
<
asp: imagebutton ID
=
"
Show
"
ImageURL
=
"
.iamgesmore.gif
"
TEXT
=
"
Check
"
CommandName
=
"
Show
"
Runat
=
"
Server
"
/>
TD
>
TR
>
ItemTemplate
>
<
AlternatingItemTemplate
>
<
Tr BGColor
=
"
# f5f2f7
"
>
<
TD
>
<
IMG SRC
=
"
.iamgesattachtb.gif
"
>
<%
# DataBinder.eval (container.dataitem,
"
CategoryID
"
)
%>
TD
>
<
TD
>
<%
# DataBinder.eval (container.dataitem,
"
CategoryName
"
)
%>
TD
>
<
TD
>
<%
# DataBinder.eval (container.dataitem,
"
Description
"
)
%>
TD
>
<
TD
>
<
asp: imagebutton ID
=
"
ImageButton1
"
ImageURL
=
"
.iamgesmore.gif
"
TEXT
=
"
Check
"
CommandName
=
"
Show
"
Runat
=
"
Server
"
/>
TD
>
TR
>
AlternatingItemTemplate
>
<
Footertemplate
>
TABLE
>
Footertemplate
>
ASP: REPEATER
>
FORM
>
Body
>
HTML
>
Private
Void
?
Connecdb ()
{SqlConnection con = new SqlConnection ( "server = localhost; database = Northwind; Trusted_Connection = Yes;"); SqlDataAdapter da = new SqlDataAdapter ( "select * from Categories", con); DataSet ds = new DataSet (); ad.Fill (DS, "categories"); this.repeater1.datasource = DS; this.repeater1.database.repeater1.database (); // Bind to the REPEATER control}
The following is an event in the REATER template
Private
Void
Repeater1_ItemCommand
Object
Sender, System.Web.ui.WebControls.RepeaterCommandeventArgs E)
{If (e.CommandName == "show") {MessageBox.Show ( "you? Click" e.Item.ItemIndex.ToString () "row", "ashow", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton .Button1, MessageBoxOptions.DefaultDesktopOnly);} else {MessageBox.Show ( "you click??" e.Item.ItemIndex.ToString () "row", "altshow", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton. Button1, MessageBoxOptions.defaultDesktoponly;}}