ASP.NET-Repeater建立table繫結資料(Repeater bind data)
最近喜歡用Repeater來建table,再套bootstrap的CSS,用起來比gridview方便。
前端
<asp:Repeater ID="rp1" runat="server">
<HeaderTemplate>
<table id="datatable-buttons" class="table table-striped table-bordered">
<thead>
<tr>
<th>圖片</th>
<th>編號</th>
<th>功能</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Image ID="Image1" runat="server" style = "position: relative, left: 9px; top: 14px;max-width: 150px;width:100%;" ImageUrl='<%# Eval("image_address") %>' /></td>
<td><%# Eval("no") %></td>
<td>
<asp:Button ID="btn_modify" runat="server" class="btn btn-primary btn-sm" CommandArgument='<%# Eval("id") %>' Text="細節" OnClick="btn_modify_Click" />
<asp:Button ID="btn_delete" runat="server" class="btn btn-danger btn-sm" CommandArgument='<%# Eval("id") %>' Text="刪除" OnClick="btn_delete_Click" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
後端
DataTable dt = new DataTable();
rp1.DataSource = dt;
rp1.DataBind();
前端
<asp:Repeater ID="rp1" runat="server">
<HeaderTemplate>
<table id="datatable-buttons" class="table table-striped table-bordered">
<thead>
<tr>
<th>圖片</th>
<th>編號</th>
<th>功能</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Image ID="Image1" runat="server" style = "position: relative, left: 9px; top: 14px;max-width: 150px;width:100%;" ImageUrl='<%# Eval("image_address") %>' /></td>
<td><%# Eval("no") %></td>
<td>
<asp:Button ID="btn_modify" runat="server" class="btn btn-primary btn-sm" CommandArgument='<%# Eval("id") %>' Text="細節" OnClick="btn_modify_Click" />
<asp:Button ID="btn_delete" runat="server" class="btn btn-danger btn-sm" CommandArgument='<%# Eval("id") %>' Text="刪除" OnClick="btn_delete_Click" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
後端
DataTable dt = new DataTable();
rp1.DataSource = dt;
rp1.DataBind();
留言
張貼留言