一、asp:Repeater
Repeater 控件用于显示被绑定在该控件上的项目的重复列表。Repeater 控件可被绑定到数据库表、XML 文件或者其他项目列表。
1.1-前台页面代码
<asp:Repeater ID="ImageTypeListNew" runat="server" OnItemCommand="ImageTypeListNew_ItemCommand">
<HeaderTemplate>
<table cellspacing="0" border="0" id="ctl00_contentHolder_ImageTypeList" class="table table-striped">
<tbody>
<tr>
<th>分类名称</th>
<th>图片数</th>
<th>排序</th>
<th style="width: 20%;">操作</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HiddenField ID="hfItemIndex" runat="server" Value='<%#Container.ItemIndex %>' />
<asp:HiddenField ID="hfCategoryId" runat="server" Value='<%#Eval("CategoryId") %>' />
<Hi:HtmlDecodeTextBox ID="ImageTypeName" runat="server" Text='<%# Bind("CategoryName") %>' CssClass="forminput form-control" Visible='<%#Eval("CategoryId").ToString()!="0" %>' />
<asp:Label ID="ltlTypeName" runat="server" Text='<%# Bind("CategoryName") %>' Visible='<%#Eval("CategoryId").ToString()=="0" %>'></asp:Label>
</td>
<td>
<%#Eval("VideoCounts") %>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DisplaySequence") %>' Visible='<%#Eval("CategoryId").ToString()=="0" %>'></asp:Label>
<asp:TextBox ID="txtDisplaySequence" runat="server" Button="btnSearchButton" CssClass="forminput form-control" value='<%# Eval("DisplaySequence") %>' Visible='<%#Eval("CategoryId").ToString()!="0" %>' onkeyup="this.value=this.value.replace(/\D/g,'')" style="width: 60px;" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
</td>
<td><span class="submit_shanchu">
<Hi:ImageLinkButton runat="server" ID="lkbtnDelete" CommandName="Delete" IsShow="true" Text="删除" Visible='<%#Eval("CategoryId").ToString()!="0" %>'/></span></td>
</tr>
</ItemTemplate>
<FooterTemplate></tbody></table></FooterTemplate>
</asp:Repeater>
1.2-后台页面代码(核心)
代码示例:
DataTable videoCategories = GalleryHelper.GetVideoCategories(0);
DataRow row = videoCategories.NewRow();
//如果数据为空,设置第一行数据
row["CategoryId"] = "0";
row["CategoryName"] = "默认分类";
row["DisplaySequence"] = "0";
row["VideoCounts"] = "0";
videoCategories.Rows.InsertAt(row, 0);
this.ImageTypeListNew.DataSource = videoCategories;
this.ImageTypeListNew.DataBind();
1.3-使用方法
在页面加载时【Page_Load】可调用,以及删除/排序/编辑等场景也可调用。
二、UI:Grid/GridView
显示表格数据是软件开发中的一个周期性任务。ASP.NET 提供了许多工具来在网格中显示表格数据,例如 GridView 控件。通过使用 GridView 控件,您可以显示、编辑和删除多种不同的数据源(例如数据库、XML 文件和公开数据的业务对象)中的数据。
1.1-前台页面代码
<UI:Grid ID="grdTopCategries" DataKeyNames="CategoryId" runat="server" ShowHeader="true" AutoGenerateColumns="false" CssClass="table table-striped" GridLines="None" Width="100%">
<Columns>
<asp:TemplateField HeaderText="分类名称">
<ItemTemplate>
<span class="icon" categoryid='<%# Eval("CategoryId") %>' parentid='<%# Eval("ParentCategoryId") %>' id="spShowImage" runat="server">
<img src="../images/jian.gif" width="24" height="24" /></span>
<span class="Name" id="spCategoryName"><a href='<%# "/product_detail/"+Eval("CategoryId")%>' target="_blank">
<asp:Literal ID="lblCategoryName" runat="server" /></a></span>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="URL重写名称" DataField="RewriteName" />
<asp:TemplateField HeaderText="排序">
<ItemTemplate>
<asp:TextBox ID="txtSequence" CssClass="form-control" runat="server" Text='<%# Eval("DisplaySequence") %>' Width="80px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="操作" HeaderStyle-CssClass="td_left td_right_fff">
<ItemTemplate>
<div class="operation">
<span><a href="javascript:ShowRemoveProduct(<%#Eval("CategoryId") %>)">转移商品</a></span>
<span><span><a href="javascript:void(0);" onclick="javascript:CollectionCategory('<%# "EditReleteCategory.aspx?ParentCategoryId="+Eval("ParentCategoryId") + "&CategoryId="+Eval("CategoryId")%>')">相关课程</a></span></span>
<span>
<asp:HyperLink ID="lkEdit" runat="server" Text="编辑" NavigateUrl='<%# "EditActivityCategory.aspx?CategoryId="+Eval("CategoryId")%>'></asp:HyperLink>
</span>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</UI:Grid>
1.2-后台页面代码(核心)
代码示例:
DataTable dt = new DataTable();
if (inviteCodeList.TotalRecords == 0)
{
dt.Columns.Add("SaleId");
dt.Columns.Add("UserId");
dt.Columns.Add("TransactionDate");
dt.Columns.Add("IncomeType");
dt.Columns.Add("TransactionNo");
dt.Columns.Add("TransactionType");
dt.Columns.Add("RefundId");
dt.Columns.Add("SaleName");
dt.Columns.Add("UserName");
dt.Columns.Add("OrderType");
dt.Columns.Add("PaymentType");
dt.Columns.Add("DeliverPrincipal");
dt.Columns.Add("CommissionRate");
dt.Columns.Add("Tax");
dt.Columns.Add("DeliverIncome");
dt.Columns.Add("ApprovedStatus");
dt.Columns.Add("Reason");
dt.Columns.Add("SettlementId");
dt.Columns.Add("Amount");
dt.Columns.Add("ApprovedStatusId");
if (dt.Rows.Count == 0)
{
dt.Rows.Add(dt.NewRow());
}
this.grdSaleInviteCode.DataSource = dt;
this.grdSaleInviteCode.DataBind();
}
标签:控件,ASP,Repeater,表头,Add,dt,页面,Columns,row
From: https://blog.51cto.com/kimiliucn/6928506