Instance code for display and layout by repeater

Source: Internet
Author: User

Front-end
Copy codeThe Code is as follows:
<Div>
<Table>
<Tr>
<Asp: Repeater ID = "Repeater1" runat = "server" OnItemDataBound = "repeaterincluitemdatabound">
<ItemTemplate>
<Td>
<Table>
<Tr>
<Td colspan = "2">
'/>
</Td>
</Tr>
<Tr>
<Td colspan = "2">
<Asp: Label ID = "Label1" runat = "server" Text = '<% # Eval ("FoodName") %>'> </asp: Label>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Label ID = "Label2" runat = "server" Text = '<% # Eval ("FoodPrice") %>'> </asp: Label>
</Td>
<Td>
<Input type = "image" src = "images/product_add.png" onclick = "product_add ()"/>
<% -- <Asp: ImageButton ID = "ImageButton1" runat = "server" ImageUrl = "images/product_add.png"/> -- %>
<Asp: TextBox ID = "TextBox1" Text = "1" runat = "server" Width = "15px" ReadOnly = "True"> </asp: TextBox>
<Input type = "image" src = "images/product_performance.png" onclick = "product_reduce ()"/>
<% -- <Asp: ImageButton ID = "ImageButton2" runat = "server" ImageUrl = "images/product_performance.png"/> -- %>
</Td>
</Tr>
<Tr>
<Th colspan = "2">
<Asp: ImageButton ID = "ImageButton3" ImageUrl = "images/btn_order.gif" runat = "server"/>
</Th>
</Tr>
</Table>
</Td>
</ItemTemplate>
</Asp: Repeater>
</Tr>
</Table>
</Div>


Background

Copy codeThe Code is as follows:
Public int I = 1;

Protected void Page_Load (object sender, EventArgs e)

{

String sqlstr = @ "data source = PC-LENOVE \ SQLEXPRESS; initial catalog = KFC; user id = SA; PASSWORD = abing520 ";

SqlConnection con = new SqlConnection (sqlstr );

SqlCommand cmd = new SqlCommand ();

Cmd. CommandText = "SELECT * FROM Foods ";

Cmd. Connection = con;

SqlDataAdapter adapter = new SqlDataAdapter (cmd );

DataTable dt = new DataTable ();

Adapter. Fill (dt );

Cmd. Dispose ();

Con. Dispose ();

This. Repeater1.DataSource = dt;

This. Repeater1.DataBind ();

}

Protected void repeaterincluitemdatabound (object sender, RepeaterItemEventArgs e)

{

If (I % 4 = 0) // 4 is the number of columns displayed in a row

{

E. Item. Controls. Add (new LiteralControl ("</tr> <tr> "));

}

I ++;

}


Related Article

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.