In continuation to my last question, I was suggested to use Repeater for displaying data fetched from SQL Db in horizontal layout.
https://stackoverflow.com/questions/25447351/asp-net-c-sharp-customized-gridview/25458682#25458682
As per suggestion I implemented a repeater control. The data was displayed in horizontal layout but only second column fetched from the DB.
How to get the first column too:
<asp:Repeater ID="RepDetails" runat="server">
<HeaderTemplate>
<asp:Literal ID="litRowStart" runat="server"></asp:Literal>
<td>
<asp:Label ID="lblExpID" runat="server" Text='<%#Eval("Exp_ID") %>' Font-Bold="true" />
</td>
<asp:Literal ID="litRowEnd" runat="server"></asp:Literal>
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="litRowStart1" runat="server"></asp:Literal>
<td>
<asp:Label ID="lblExpAmt" runat="server" Text='<%#Eval("Amt_Allocated") %>' Font-Bold="true" />
</td>
<asp:Literal ID="litRowEnd1" runat="server"></asp:Literal>
</ItemTemplate>
</asp:Repeater>
Create your repeater like this:
<table>
<tr>
<asp:Repeater ID="repTest" runat="server">
<ItemTemplate>
<td>
<div>
<b>
<%#Eval("NameofColumnYOuWantToShowAsHeader") %>
</b>
</div>
<div>
<%#Eval("YourColumnValue") %>
</div>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>
For more information about repeater:
Repeater Insert, Update, Delete in asp .net
Try this one using AlternateingItemTemplate:
<asp:Repeater ID="RepDetails" runat="server">
<ItemTemplate>
<td>
<asp:Literal ID="litRowStart" runat="server"></asp:Literal>
<asp:Label ID="lblExpID" runat="server" Text='<%#Eval("Exp_ID") %>' Font-Bold="true" />
<asp:Literal ID="litRowEnd" runat="server"></asp:Literal>
</td>
</ItemTemplate>
<AlternatingItemTemplate>
<td>
<asp:Literal ID="litRowStart1" runat="server"></asp:Literal>
<asp:Label ID="lblExpAmt" runat="server" Text='<%#Eval("Amt_Allocated") %>' Font-Bold="true" />
<asp:Literal ID="litRowEnd1" runat="server"></asp:Literal>
</td>
</AlternatingItemTemplate>
</asp:Repeater>
Assuming that you're getting 2 rows in your datasource.
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>
I have following code in .aspx
<asp:UpdatePanel ID="upnGrid" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rpt1" runat="server" OnItemDataBound="rpt1_ItemDataBound">
<ItemTemplate>
<table width="100%">
<tr>
<td align="right" width="25%">
<asp:Label ID="lbl1" Font-Bold="true" Font-Size="16px" Text=' <%# DataBinder.Eval(Container.DataItem,"Name") %>'
runat="server" />
</td>
<td>
<asp:HiddenField ID="hdn1" Value='<%# DataBinder.Eval(Container.DataItem, "Length") %>'
runat="server" />
</td>
<td>
<asp:TextBox ID="txt1" Font-Size="16px" Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
AutoPostBack="true" Width="100px" OnTextChanged="txt1_TextChanged" runat="server" onkeydown="javascript:return OntxtEnter(event);"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<%--<Triggers>
<asp:AsyncPostBackTrigger ControlID="rpt1"/>
</Triggers>--%>
</asp:UpdatePanel>
code for UpdateProgress is at the end of aspx -
<asp:Panel ID="UpdateProgressPanel" runat="server">
<center>
<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="upnGrid"
DynamicLayout="true">
<ProgressTemplate>
<img src="../Images/loading.gif" alt="">
</ProgressTemplate>
</asp:UpdateProgress>
</center>
</asp:Panel>
<ajaxtoolkit:modalpopupextender id="ModalProgress" runat="server" targetcontrolid="UpdateProgressPanel"
popupcontrolid="UpdateProgress2" dropshadow="false" backgroundcssclass="modalBackground">
</ajaxtoolkit:modalpopupextender>
As suggested by some answers I made AsyncPostBackTrigger to be registered in code behind, like -
var control = e.Item.FindControl("txt1");
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(control);
I am not getting, why it is not working.
Please suggest.
Edit
I tried putting only required textbox in UpdatePanel, It is showing following error
'System.Web.UI.Control' does not contain a definition for 'DataItem' and no extension method 'DataItem' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?)
Try modifying your UpdateProgress control as shown below:
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:Panel ID="Panel2" runat="server">
<asp:ImageButton ID="ibProgress" runat="server" ImageUrl="~/Images/progress.gif"
Visible="true" />Loading...
</asp:Panel>
</asp:Panel>
</ProgressTemplate>
</asp:UpdateProgress>
You cannot use it in such a way. Because inside the repeater the TextBox ID is different.You have to follow different mechanism.
I am working on a website where i need to search for items from database and display it in page.I am using Datalist for displaying all the items .Now i need to display all the items according to some category.For example if i search for a two-wheeler it may have many categories or manufacturer's.Now I want to display it separately according to the categories.I can use many datalist to do that,but it will slow down the site.Instead which control can i use to do this.I searched the web but got no idea.So please give me sugessions to go about it.Any sugessions will be appreciated.
Code:
<asp:DataList ID="Dlitems" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
CellPadding="0" CellSpacing="15">
<ItemTemplate>
<table>
<tr>
<td>
<asp:ImageButton ID="ImgbtnProductImage" CssClass="imgdisp" ImageUrl='<%# Eval("ImagePath") %>'
CommandArgument='<%#Eval("ProductCode") %>' runat="server" CommandName="cmdView" />
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td width="20px"></td>
<td>
<img src="../Database/images/inr.jpg" alt="addtocart" />
<asp:Label ID="lblproductprice" runat="server" Text='<%# Eval("Price") %>' CssClass="lbl" />
</td>
<td>
<asp:ImageButton ID="imgbtnaddtocart" runat="server" Height="25px" Width="25px" ImageUrl="~/Database/images/addtocart.JPG"
ToolTip="Add to Cart" CommandArgument='<%#Eval("ProductCode")+","+ Eval("ProductName")+","+ Eval("ImagePath")+","+ Eval("Price")+","+ Eval("LongDescription") %>'
CommandName="addtocart" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
You can take benefit of gridview.
Bind you gridview data.
And letter merge the rows.
For an example you can use the below link
http://www.codeproject.com/Articles/34337/How-to-merge-cells-with-equal-values-in-a-GridView
Edit 1
Some links
How to display group data separately using DataList in ASP.NET?
http://aspnettuts.wordpress.com/2010/10/21/asp-net-repeater-group-recordsdata-delete-selected-rows/
You should go for a Repeater control.
Example on Repeater
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<asp:ImageButton ID="ImgbtnProductImage" CssClass="imgdisp" ImageUrl='<%# Eval("ImagePathForTwoWheeler")%> + <%# Eval("ImagePathForCategory") %>'
CommandArgument='<%#Eval("ProductCode") %>' runat="server" CommandName="cmdView" />
</ItemTemplate>
</asp:Repeater>
I have an asp.net Repeater control .I have to display only 5 rows in the repeater. I searched about it in Google but most of the resources are talking about how to do it with DataSet. In my case, I am using SqlDataSource. So I can have paging in this Repeater control?
ASP.NET Code:
<asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource3">
<HeaderTemplate>
<div>
<table border="1">
<thead>
<tr>
<td colspan="3">
<center> <strong>Safety Quizzes Record</strong> </center>
</td>
</tr>
<tr>
<td>
<center> <strong>Quiz Title</strong> </center>
</td>
<td>
<center> <strong>Date & Time</strong> </center>
</td>
<td>
<center> <strong>Score</strong> </center>
</td>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<p>
<%# Eval("Title") %>
</p>
</td>
<td>
<p>
<%# Eval("DateTimeComplete") %>
</p>
</td>
<td>
<p>
<%# Eval("Score") %>
</p>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</div>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="SELECT dbo.Quiz.Title, dbo.UserQuiz.DateTimeComplete, dbo.UserQuiz.Score
FROM dbo.employee INNER JOIN
dbo.UserQuiz ON dbo.employee.Username = dbo.UserQuiz.Username INNER JOIN
dbo.Quiz ON dbo.UserQuiz.QuizID = dbo.Quiz.QuizID
WHERE (dbo.employee.Username = #Username)">
<SelectParameters>
<asp:Parameter Name="Username" />
</SelectParameters>
</asp:SqlDataSource>
UPDATE:
What I want is showing only 5 items in the Repeater and the others will be listed on the other pages of the Repeater. So how I can have Pagining with SqlDataSource as mentioned above.
The Repeater control does not support paging out-of-the-box.
You could however implement it but it would require you to manually code it.
I would like to recommend you to change the Repeater control for the ListView control
Differences:
Repeater. This control does not support paging, updating, inserting or deleting operations out-of-the-box, if you want these features you would need to manually code them.
ListView. This is the most flexible of all data-bound controls. It's based on templates like the Repeater and DataList controls. It does support CRUD operations automatically mapping the operations agains your data source control. It does support server paging, and you can customize pretty much everything
BTW, since you are using a SqlDataSource, you would have to manually add paging code to your queries or store procedures, you could change that behavior if you use a LinqDataSource or an EntityDataSource
This is a simplified ListView markup:
<asp:ListView runat="server" ID="lv"
DataSourceID="lds" DataKeyNames="emp_id"
EnableModelValidation="false"
EnablePersistedSelection="false"
>
<LayoutTemplate>
<br />
<br />
A static header
<div runat="server" id="itemPlaceHolder"></div>
<br />
<asp:DataPager runat="server" PageSize="4">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowFirstPageButton="true"
ShowLastPageButton="true"
/>
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div style="background-color:Gray">
First Name
<div><asp:Label runat="server" ID="lbl" Text='<%# Eval("fname") %>'></asp:Label></div>
<br />
<asp:GridView ID="GridView1" runat="server" DataSource='<%# Eval("Achivements") %>' />
<br />
<asp:LinkButton ID="LinkButton1" Text="Select" CommandName="Select" runat="server" />
<asp:LinkButton ID="LinkButton2" Text="Edit" CommandName="Edit" runat="server" />
<asp:LinkButton ID="LinkButton4" Text="Delete" CommandName="Delete" runat="server" />
</div>
</ItemTemplate>
<ItemSeparatorTemplate>
<hr />
</ItemSeparatorTemplate>
</asp:ListView>
Please use the PagedDataSource shown at link http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.pageddatasource.aspx
Just like we have pagesize property in gridview that allows us to switch back and forth between pages, isn't there anyway i can incorporate the same functionality in a repeater.
<table id="myTable">
<tbody>
<asp:Repeater ID="Repeater1" runat="server"
onitemcommand="addItem_OnClick" DataMember="DefaultView">
<ItemTemplate>
<tr>
<td>
<div class="product">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td width="105"><asp:HyperLink ID="HLSysDet" runat="server"
NavigateUrl='<%# "/Product.aspx?productId=" + Eval("ProductDescriptionId") %>'>
<asp:Image ID="Image1" runat="server" width="85" height="85"
ImageUrl='<%# Eval("Thumbnail")%>' border="0" />
</asp:HyperLink></td>
<td><ItemTemplate><a
href='<%# "/Product.aspx?productId=" + Eval("ProductDescriptionId") %>'>
'<%# Eval("ProductName")%>'</a> </ItemTemplate></b><br />
<br />
Manufacturer: <%# Eval("Manufacturer")%><br />
<br />
<b>Rs <%# Eval("UnitPrice")%>
</b><br />
<br />
Weight: <%# Eval("Weight")%> Kg<br />
</td>
<td width="20"></td>
<td valign="bottom" width="130">
<%# Eval("Quantity")%>+ in stock<br />
<asp:TextBox ID="_qty" runat="server" CssClass="textbox"
MaxLength="2" Text="1" Width="30"
Visible='<%# showBtn(Eval("Quantity")) %>' /> <asp:RangeValidator
ID="RangeValidator1" runat="server" ControlToValidate="_qty"
ErrorMessage="*" ForeColor="Red" MaximumValue="50"
MinimumValue="1"></asp:RangeValidator>
<div class="buttons"><span id="Span1" class="mandatory"
runat="server" visible='<%# isQty(Eval("Quantity")) %>'>
Sorry, this item is out of stock</span></div>
<div class="buttons"><br />
<asp:LinkButton ID="CommandButton" runat="server"
Text='Add to Cart' CssClass="positive" CommandName="Add"
CommandArgument='<%# Eval("ProductDescriptionId") %>'
Visible='<%# showBtn(Eval("Quantity")) %>' />
</div>
</td>
</tr>
</div>
</table>
</div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
<div class='pager'><a href='#' alt='Previous' class='prevPage'>Prev</a>
<span class='currentPage'></span> of <span class='totalPages'></span> <a
href='#' alt='Next' class='nextPage'>Next</a></div>
Check out http://plugins.jquery.com/project/paginateTable.
It's basically pagination on a html table ( which you can build using a repeater ) using jQuery.
It's easy to use, has customization options.
I used it already, worked just fine.
EDIT
You'd have to build your table with a repeater. I've provided a quick example below:
<table id="myTable">
<tbody>
<asp:Repeater ...>
<ItemTemplate>
<tr><td><%# Eval('Description') %></td></tr>
</ItemTemplate>
</asp:Repeater>
<tbody>
</table>
<div class='pager'>
<a href='#' alt='Previous' class='prevPage'>Prev</a>
<span class='currentPage'></span> of <span class='totalPages'></span>
<a href='#' alt='Next' class='nextPage'>Next</a>
</div>
Your javascript should then call the paginateTable function on this
<script>
$(document).ready(function () {
$('#myTable').paginateTable({ rowsPerPage: 2 });
});
</script>
Repeater and control offers a quick and flexible means of displaying data on a ASPX page. But it offers no paging functionality built in.
However you may do something about that ...
Refer to the following page if you like to figure it out:
http://www.codeproject.com/KB/webforms/Aspnet_Repeater_Control.aspx
You can use PagedDataSource.
Repeater with Paging and Sorting Features
Paging Repeater Control using PagedDataSource