I have a list that contains names.
I would like to create a listview that will display these name, three to a row.
I am unsure how to accomplish this.
You should use a GroupTemplate. Here's an example from 4GuysFromRolla.com
<asp:ListView ID="ProductList1" runat="server"
DataSourceID="ProductDataSource"
GroupItemCount="3" ItemPlaceholderID="itemsGoHere"
GroupPlaceholderID="groupsGoHere">
<LayoutTemplate>
<p>
<asp:PlaceHolder runat="server" ID="groupsGoHere"></asp:PlaceHolder>
</p>
</LayoutTemplate>
<GroupTemplate>
<ol>
<asp:PlaceHolder runat="server" ID="itemsGoHere"></asp:PlaceHolder>
</ol>
</GroupTemplate>
<ItemTemplate>
<li><%#Eval("ProductName")%></li>
</ItemTemplate>
</asp:ListView>
Related
I am still new in asp.net c# and want to display a listview with 2 items in a row. However, the listview is not displayed with 2 items in a row even though I use GroupItemCount. Can anyone tell me how to solve it?
Thank you in advance.
<asp:ListView ID="lvClientFacility" runat="server" DataSourceID="SqlDataSource1" DataKeyName="facility_id" GroupItemCount="2" GroupPlaceholderID="groupPlaceholder1" ItemPlaceholderID="itemPlaceholder1">
<LayoutTemplate>
<div>
<asp:PlaceHolder ID="groupPlaceholder1" runat="server" />
</div>
</LayoutTemplate>
<GroupTemplate>
<div>
<asp:PlaceHolder ID="itemPlaceholder1" runat="server" />
</div>
</GroupTemplate>
<ItemTemplate>
<a class="facility" href="clientReservation.aspx?Id=<%# Eval("facility_id")%>">
<asp:Image ID="Image1" runat="server" Height="200px" Width="250px" ImageUrl='<%#"data:img/jpg;base64," + Convert.ToBase64String((byte[])Eval("facility_image"))%>' />
<div class="facilityName"><%# Eval("facility_name")%></div>
<asp:LinkButton ID="LinkButton1" PostBackUrl= '<%# "clientReservation.aspx?facility_id=" + Eval("facility_id") %>' runat="server" Text="Book Now"/>
<div class="ClientFacilityDescription"><%# Eval("facility_description")%></div>
</a>
</ItemTemplate>
</asp:ListView>
In asp.net C# webform Have a list view with one button after binding it convert to many buttons dynamically want to highlight selected button
<asp:ListView ID="ListViewCompanyServicesList" runat="server" ItemPlaceholderID="itemPlaceHolder" OnItemCommand="ListViewCompanyServicesList_ItemCommand">
<LayoutTemplate>
<div id="itemPlaceHolder" runat="server" style="margin-bottom: 0px;">
</div>
</LayoutTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnTags" runat="server" Text='<%# Eval("Service") %>' CommandName="SelectService" CommandArgument='<%# Eval("ServiceId") %>' CssClass="label label-default" Style="display: inline-block" OnClick="btnTags_Click" />
</ItemTemplate>
<EmptyDataTemplate>
<div class="promote_contentBox2">
<p class="well" style="font-size: 80%;">No record Found</p>
</div>
</EmptyDataTemplate>
</asp:ListView>
You can change the css of the button that has been clicked.
btnTags.CssClass="your custom class";
I want to create asp:Table where I can add rows using asp:Repeater like:
<asp:Table runat="server" ID="tblRepeater">
<asp:Repeater runat="server">
<ItemTemplate>
<asp:TableRow runat="server">
<asp:TableCell runat="server" Text=""></asp:TableCell>
<asp:TableCell runat="server" Text=""></asp:TableCell>
</asp:TableRow>
</ItemTemplate>
</asp:Repeater>
</asp:Table>
But when I try to do this It gives me error:
System.Web.UI.WebControls.TableRowCollection must have items of type 'System.Web.UI.WebControls.TableRow'.
'asp:Repeater' is of type 'System.Web.UI.WebControls.Repeater'.
Am I doing somethig wrong or it is impossible to use Repeater in Table?
I'm not sure if your example is slimmed down or represents your actual use case, but in this case you'd be better of using either a GridView which will generate a table structure based off of a given Data Source, or creating the <table> structure yourself and then placing a repeater inside it:
<table>
<asp:Repeater runat="server">
<ItemTemplate>
<tr>
<td><asp:TextBox runat="server" /></td>
<td><asp:TextBox runat="server" /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
I'm using a SqlDataSource to bring back data to be displayed in a drop down. The headers of each drop down is the brand and in the drop down I want three products of each brand to be brought back.
<asp:SqlDataSource ID="Categories" runat="server" ConnectionString="<%$ ConnectionStrings:Categories %>" SelectCommand="SELECT * FROM CATEGORY WHERE CategoryID <5"></asp:SqlDataSource>
<asp:ListView ID="ListView2" runat="server" DataSourceID="Categories">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:SqlDataSource ID="images" runat="server" ConnectionString="<%$ ConnectionStrings:Categories %>" SelectCommand="SELECT * FROM ITEM ORDER BY Category_ref"></asp:SqlDataSource>
<li id="<%# Eval("CategoryName") %>">
<%# Eval("CategoryName") %>
<div class="dropDown">
<div class="listItem">
<asp:ListView ID="listview3" runat="server" DataSourceID="images">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ItemID","Product.aspx?id={0}") %>'>
<p class="<%# Eval("Category_ref", "brand{0}") %>">
<asp:Image ID="image" CssClass="dropImg" runat="server" ImageUrl='<%# Eval("PhotoPath", "images/products/{0}") %>' />
<br />
<span><%# Eval("ItemName") %></span>
<%# Eval("ItemID").ToString() %>
</p>
</asp:HyperLink>
</ItemTemplate>
</asp:ListView>
</div>
</div>
</li>
</ItemTemplate>
</asp:ListView>
That is my entire navigation with the brand names coming back from database as well as the product information.
The second SqlDataSource query is where I need to fix up so it only selects 3 product. If there is a fourth it will leave it out.
In SQL Server:
SELECT TOP 3 * FROM ITEM ORDER BY Category_ref
In MySQL:
SELECT * FROM ITEM ORDER BY Category_ref LIMIT 3
You should always specify your database of choice with your question, and reduce the problem to the essence (all that ASP code is irrelevant and just scares people from your question).
In an ASP:ListView I want to pass an entire object to a child control within the ItemTemplate, not just a single property of the current object.
Here is the code I want to work:
<asp:ListView ID="answers" runat="server">
<LayoutTemplate>
<div id="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<div>
<uc2:DocumentHeader runat="server" Document="Eval(%# Eval("this") %> />
<p><%# Eval("Body") %></p>
</div>
</ItemTemplate>
</asp:ListView>
The Document property of the DocumentHeader expects the entire Document object, whereas "Body" is a property of Document.
Obviously, I could just create a new property within Document or use a LINQ query to generate a new class with the property I want, I just want to know if there is an easier, more direct way to get what I want.
You can bind the context object using <%# Container.DataItem %>. You probably will need to cast it to whatever "Document" expects.
<asp:ListView ID="answers" runat="server">
<LayoutTemplate>
<div id="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<div>
<uc2:DocumentHeader runat="server" Document="<%# Container.DataItem %>" />
<p><%# Eval("Body") %></p>
</div>
</ItemTemplate>
</asp:ListView>