1. asp:Repeater
The Repeater control is used to display a repeating list of items bound to the control. Repeater controls can be bound to database tables, XML files, or other lists of items.
1.1-Foreground page code
<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>Category name</th> <th>number of images</th> <th>sort</th> <th style="width: 20%;">Operation</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="Delete" Visible='<%#Eval(" CategoryId").ToString()!="0" %>'/></span></td> </tr> </ItemTemplate> <FooterTemplate></tbody></table></FooterTemplate> </asp:Repeater>
1.2- Background page code (core)
Code example:
DataTable videoCategories = GalleryHelper. GetVideoCategories(0); DataRow row = videoCategories. NewRow(); //If the data is empty, set the first row of data row["CategoryId"] = "0"; row["CategoryName"] = "Default Category"; row["DisplaySequence"] = "0"; row["VideoCounts"] = "0"; videoCategories.Rows.InsertAt(row, 0); this.ImageTypeListNew.DataSource = videoCategories; this.ImageTypeListNew.DataBind();
1.3-How to use
[Page_Load] can be called when the page is loaded, and scenes such as deletion/sorting/editing can also be called.
2. UI: Grid/GridView
Displaying tabular data is a recurring task in software development. ASP.NET provides many tools to display tabular data in a grid, such as the GridView control. By using the GridView control, you can display, edit, and delete data from a variety of different data sources such as databases, XML files, and business objects that expose data.
1.1-Foreground page code
<UI:Grid ID="grdTopCategries" DataKeyNames="CategoryId" runat="server" ShowHeader="true" AutoGenerateColumns="false" CssClass="table table-striped " GridLines="None" Width="100%"> <Columns> <asp:TemplateField HeaderText="Category Name"> <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 Rewrite Name" DataField="RewriteName" /> <asp:TemplateField HeaderText="Sort"> <ItemTemplate> <asp:TextBox ID="txtSequence" CssClass="form-control" runat="server" Text='<%# Eval("DisplaySequence") %>' Width=" 80px" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Operation" HeaderStyle-CssClass="td_left td_right_fff"> <ItemTemplate> <div class="operation"> <span><a href="javascript:ShowRemoveProduct(<%#Eval("CategoryId") %>)">Remove Product</a></span> <span><span><a href="javascript:void(0);" onclick="javascript:CollectionCategory('<%# "EditReleteCategory.aspx?ParentCategoryId=" + Eval("ParentCategoryId ") + " & amp;CategoryId=" + Eval("CategoryId")%>')">Related courses</a></span></span> <span> <asp:HyperLink ID="lkEdit" runat="server" Text="Edit" NavigateUrl='<%# "EditActivityCategory.aspx?CategoryId=" + Eval("CategoryId" )%>'></asp:HyperLink> </span> </div> </ItemTemplate> </asp:TemplateField> </Columns> </UI:Grid>
1.2- Background page code (core)
Code example:
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(); }
Copyright statement: This article is an original article, and the copyright belongs to [Watermelon Programmer]. Please indicate the source for reprinting. If you have any questions, please consult by private message.
Original link: How to display the table header when asp:Repeater and UI:Grid data in ASP.NET WebForm is empty? _Watermelon Programmer’s Blog-CSDN Blog