Using the Repeater template

Source: Internet
Author: User
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:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.