Repeater control usage-a method for displaying a fixed record on each row of a column of data in Repeater

Source: Internet
Author: User

<Asp: repeater id = "rptstatus" runat = "server" onitemdatabound = "rptstatus_itemdatabound">
<Headertemplate>
<Table>
<Tr>
</Headertemplate>
<Itemtemplate>
<TD>
<Asp: Image id = "imgstatus" runat = "server" tooltip = '<% # eval ("vehicle status") %>'/>
</TD>
<TD>
<Asp: Label id = "lblcph" runat = "server" text = '<% # eval ("license plate number") %>'> </ASP: Label>
</TD>
</Itemtemplate>
<Footertemplate>
</Tr>

</Table>
</Footertemplate>
</ASP: repeater>

 

 

Private int I = 0;

Protected void rptstatus_itemdatabound (Object sender, repeateritemeventargs E)
{

// Reset the imageurl attribute value based on the tooltip attribute value of the image to indicate the vehicle usage status.
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
Image image = (image) E. Item. findcontrol ("imgstatus ");
Int tooltip = int. parse (image. tooltip. tostring ());
If (tooltip = 0)
{
Image. imageurl = "~ /Images/ky.jpg ";
}
Else if (tooltip = 1)
{
Image. imageurl = "~ /Images/cc.jpg ";
}
Else if (tooltip = 2)
{
Image. imageurl = "~ /Images/wx.jpg ";
}
Else if (tooltip = 3)
{
Image. imageurl = "~ /Images/qt.jpg ";
}
}
If (I % 7 = 0 & I> 0)
{
E. Item. Controls. Add (New literalcontrol ("</tr> <tr> "));
}
I ++;
}

 

// Bind the Repeater control
Private void bindrepeater ()
{
Dbhandler DBH = dbhandlerfactory. gethandler ("vehicleconnectionstring ");
DBH. commandtext = "select license plate number, vehicle status from vehicle portfolio ";
Datatable dt = DBH. executedatatable ();
This. rptstatus. datasource = DT;
This. rptstatus. databind ();
}

 

The display 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.