repeater 分列顯示以及布局的實例代碼
前臺
<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>
后臺
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顯示某列總計思路與代碼
- Repeater控件動態(tài)變更列(Header,Item和Foot)信息實現(xiàn)思路
- Repeater對數(shù)據(jù)進行格式化處理
- Repeater全選刪除和分頁實現(xiàn)思路及代碼
- ASP.NET中repeater嵌套實現(xiàn)代碼(附源碼)
- Repeater與ListView功能概述及使用介紹
- Repeater控件數(shù)據(jù)導出Excel(附演示動畫)
- asp.net中讓Repeater和GridView支持DataPager分頁
- 在jquery repeater中添加設置日期,下拉,復選框等控件
- Repeater控件動態(tài)變更列(Header,Item和Foot)信息(重構cs)
相關文章
ASP.NET Web應用程序出現(xiàn)Maximum request length
ASP.NET Web應用中導出數(shù)據(jù)時出現(xiàn)500-Internal Server Error,原因是客戶端請求長度超過了服務器配置的最大限制,解決方法在web.config增加maxRequestLength屬性,單位為字節(jié)(Byte),本文介紹ASP.NET Web應用程序出現(xiàn)Maximum request length exceeded報錯的原因,一起看看吧2024-12-12
詳解MVC中為DropDownListFor設置選中項的方法
這篇文章主要介紹了詳解MVC中為DropDownListFor設置選中項的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
asp.net通過HttpModule自動在Url地址上添加參數(shù)
由于項目中有許多頁面需要用到cid參數(shù),所以想通過傳值cid來獲取數(shù)據(jù)。2010-01-01

