repeater 分列顯示以及布局的實(shí)例代碼
前臺(tái)
<div>
<table>
<tr>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<td>
<table>
<tr>
<td colspan="2">
<img src='<%#"images/"+Eval("FoodPicture") %>' />
</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_reduce.png" onclick="product_reduce()" />
<%--<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="images/product_reduce.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>
后臺(tái)
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 Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (i % 4 == 0)//4是一行顯示列數(shù)
{
e.Item.Controls.Add(new LiteralControl("</tr><tr>"));
}
i++;
}
- Repeater的FooterTemplate顯示某列總計(jì)思路與代碼
- Repeater控件動(dòng)態(tài)變更列(Header,Item和Foot)信息實(shí)現(xiàn)思路
- Repeater對(duì)數(shù)據(jù)進(jìn)行格式化處理
- Repeater全選刪除和分頁(yè)實(shí)現(xiàn)思路及代碼
- ASP.NET中repeater嵌套實(shí)現(xiàn)代碼(附源碼)
- Repeater與ListView功能概述及使用介紹
- Repeater控件數(shù)據(jù)導(dǎo)出Excel(附演示動(dòng)畫(huà))
- asp.net中讓Repeater和GridView支持DataPager分頁(yè)
- 在jquery repeater中添加設(shè)置日期,下拉,復(fù)選框等控件
- Repeater控件動(dòng)態(tài)變更列(Header,Item和Foot)信息(重構(gòu)cs)
相關(guān)文章
ASP.NET Web應(yīng)用程序出現(xiàn)Maximum request length
ASP.NET Web應(yīng)用中導(dǎo)出數(shù)據(jù)時(shí)出現(xiàn)500-Internal Server Error,原因是客戶端請(qǐng)求長(zhǎng)度超過(guò)了服務(wù)器配置的最大限制,解決方法在web.config增加maxRequestLength屬性,單位為字節(jié)(Byte),本文介紹ASP.NET Web應(yīng)用程序出現(xiàn)Maximum request length exceeded報(bào)錯(cuò)的原因,一起看看吧2024-12-12
詳解MVC中為DropDownListFor設(shè)置選中項(xiàng)的方法
這篇文章主要介紹了詳解MVC中為DropDownListFor設(shè)置選中項(xiàng)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
狀態(tài)保存機(jī)制之ViewState概述及應(yīng)用
無(wú)狀態(tài)的根本原因是:瀏覽器和服務(wù)器使用Socket通信,服務(wù)器將請(qǐng)求結(jié)果返回給瀏覽器后,會(huì)關(guān)閉當(dāng)前Socket連接,接下來(lái)介紹狀態(tài)保存機(jī)制,感興趣的朋友可以了解下2013-02-02
asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù)
由于項(xiàng)目中有許多頁(yè)面需要用到cid參數(shù),所以想通過(guò)傳值cid來(lái)獲取數(shù)據(jù)。2010-01-01
jquery中如何獲得服務(wù)器控件實(shí)現(xiàn)思路
jquery中如何獲得服務(wù)器控件,很多新手朋友對(duì)此比較陌生,接下來(lái)為您介紹解決方法,感興趣的朋友可以了解下哦2013-01-01

