Template note) The following code is the code for the page, and only the repeater part of the code is pasted, because you want to bind the data, such as () so before you can use it, import the name space first
<asp:repeater id= "Repeater1" runat= "Server" >
<HeaderTemplate>
<table?border= "0" >
<tr?bgcolor= "#999999" >
<td> Product Type idtd>
<td> Product Type name td><td> Product type description td>
<td> td>
<tr>
<HeaderTemplate>
<ItemTemplate>
<tr?bgcolor= #ffffff >
<td>
<td>
<td>
<td>
<td>td>
<td><asp:imagebutton id= "Show" Imageurl= ". \iamges\more.gif"
Commandname= "Show" runat= "Server"/>td>
<tr>
<ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor= #f5f2f7 >
<td>
<td>
<td>td>
<td>td>
<td><asp:imagebutton id= "Imagebutton1" imageurl= ". \iamge\smore.gif"
Commandname= "Show" runat= "Server"/>
<td>
<tr>
Alternatingitemtemplate>
<FooterTemplate>
<table>
<FooterTemplate>
Asp:repeater>form>
<body>
<HTML>
Post Code section:
First Import name space: Using System.Data.SqlClient and Using System.Windows.Forms, and other systems by default
The following is the code for the Connection library:
?
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.databind ()//bound to Repeater control
}
The following section is an event in the Repeater 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", "a
Show ", 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);
}
}
(Note: 1, must bind the above method to its ItemCommand event in the Repeater template event, can do 2 in the event window, the picture URL above should be imageurl= ". \iamges\more.gif", because the blog has a problem with the code support , so it was automatically intercepted.)
The final effect is as follows: