How to add caption and sum a column? - c#

i want give caption DATE,PRICE1, PRICE2 and i also show sum of price1, price2 in the footer. how can i do this?
<asp:Repeater ID="rptCari" runat="server">
<ItemTemplate>
<div>
<tr>
<td>
<asp:Label runat="server" ID="lblBelgeTarihi"><%#(Eval("DATE","{0:d}"))%></asp:Label>
</td>
<td>
</td>
<td>
<asp:Label runat="server" ID="lblAlacakTutar"><%#ValidationHelper.FormatPrice(ValidationHelper.GetDecimal(Eval("PRICE1"), 0))%></asp:Label>
</td>
<td>
</td>
<td>
<asp:Label runat="server" ID="lblBorcTutar"><%#ValidationHelper.FormatPrice(ValidationHelper.GetDecimal(Eval("PRICE2"), 0))%></asp:Label>
</td>
</tr>
</div>
</ItemTemplate>
</asp:Repeater>

You've HeaderTemplate and FooterTemplate as child elements of Repeater.

Related

Creating a table column by column with repeater

I'm trying to make a comparison table for a website. There is a repeater which has a list of objects as the datasource.
The table will need to look like so:
Product1 Product2 Product3
ProductName1 ProductName2 ProductName3
ProductImage1 ProductImage2 ProductImage3
The problem is that I have the <tr> and <td> tags in the repeater and this causes the ProductNames to not be in the same row, so I get this:
Product1
ProductName1
ProductImage1
Product2
ProductName2
ProductImage2
Product3
ProductName3
ProductImage3
Is there a way to fill in the table column by column with the different items being in the same row?
Edit (added code):
<asp:PlaceHolder runat="server" ID="phPopUp">
<div id="popup-wrapper">
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<HeaderTemplate>
<table class="table-wrapper">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>
</td>
</tr>
<tr>
<td class="product-image">
<img src='<%# URLHelper.GetAbsoluteUrl(((PPG.Ecommerce.CategoryProduct)Container.DataItem).ProductImage) %>'
alt='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>'
title='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>' />
</td>
</tr>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Features") %>
</td>
</tr>
<tr>
<td>
<%-- Features --%>
<asp:Literal runat="server" ID="ltFeatures" />
</td>
</tr>
<%-- <tr>
<td>
<asp:Literal ID="ltApplication" runat="server" />
</td>
</tr>--%>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.ColorType") %>
</td>
</tr>
<tr>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).EcomProduct.ProductColorType %>
</td>
</tr>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</tr>
<tr>
<td>
<asp:Literal ID="colors" runat="server" />
<asp:BulletedList runat="server" ID="blColors" />
</td>
</tr>
<tr>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</tr>
<tr>
<td>
<asp:Literal runat="server" ID="ltVolumes" />
</td>
</tr>
<tr>
<td>
<%-- substrate --%>
</td>
</tr>
<tr>
<td>
<%-- finish --%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
repeat the repeater in each row:
<asp:PlaceHolder runat="server" ID="phPopUp">
<div id="popup-wrapper">
<table class="table-wrapper">
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td class="product-image">
<img src='<%# URLHelper.GetAbsoluteUrl(((PPG.Ecommerce.CategoryProduct)Container.DataItem).ProductImage) %>'
alt='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>'
title='<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).PageTitle %>' />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Features") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%-- Features --%>
<asp:Literal runat="server" ID="ltFeatures" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<%-- <tr>
<td>
<asp:Literal ID="ltApplication" runat="server" />
</td>
</tr>--%>
<tr>
<asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.ColorType") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ((PPG.Ecommerce.CategoryProduct)Container.DataItem).EcomProduct.ProductColorType %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<asp:Literal ID="colors" runat="server" />
<asp:BulletedList runat="server" ID="blColors" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%# ResHelper.GetString("PPGEcomUk.ProductCompare.Colors") %>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<asp:Literal runat="server" ID="ltVolumes" />
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%-- substrate --%>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<tr><asp:Repeater runat="server" ID="rptProductInfo" OnItemDataBound="rptProductInfo_ItemDataBound">
<ItemTemplate>
<td>
<%-- finish --%>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>

Showing comments without reloading page

The code below get me a comment , puts it in the database and then waits for a page reload to show the comment. How can i make the submited comment to be shown right after it has been posted along with the new ones ? This is the code that does the stuff :
Layout:
<table>
<tr>
<td colspan="2">All Comments</td>
<td>
&nbsp
</td>
</tr>
<tr> <td colspan="2"> </td></tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments" >
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label id="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</td>
</tr>
<td>
<table>
<tr>
<td colspan="2" >Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>
&nbsp
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>
&nbsp
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>
&nbsp
</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
Code Behind:
public void fnSubmitComment()
{
AddComment cmt = new AddComment();
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
bool addSucces = cmt.Addcomment( y , txtcomment.Text);
if (addSucces)
{
lblStatus.Text = "Your Comment has been Added Successfully.";
}
else
{
lblStatus.Text = "Your Comment has not been Added.";
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
fnSubmitComment();
}
public IQueryable<Comments> GetComments()
{
var _db = new SiteStiri.Models.CommentsContext();
IQueryable<Comments> query = _db.Comments;
String x = Request.QueryString["newsID"].ToString();
int y = Convert.ToInt32(x);
query = query.Where(p => p.NewsID == y);
return query;
}
I heard i can do that with ajax ? (My knowledge about ajax is 0 currently) Any tips on how i can do this ?
You must wrapper you repeater in an updatepanel,
set UpdateMode="Conditional" and add a trigger on btnSubmit so when click the button the update the repeater with the normal page life cycle
Remember to bind the repeater after that you add the commet in the codebehind and must be present in your page a ScriptManager control
more or less thus
<asp:ScriptManager runat="server" />
<table>
<tr>
<td colspan="2">All Comments</td>
<td>&nbsp
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" ItemType="SiteStiri.Models.Comments" SelectMethod="GetComments">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lblDate" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblComment" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="Label1" runat="server" Text='<%# Item.ReleaseDate %>'></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label2" runat="server" Text='<%# Item.Comment %>'>
</asp:Label>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td colspan="2">Add Your Comment</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Visible="False"></asp:Label>
</td>
<td>&nbsp
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine">
</asp:TextBox>
</td>
<td>&nbsp
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
<td>&nbsp
</td>
</tr>
</table>
</td>
</tr>
</table>

customise gridview display when bound to a datasource

I want to display the values in a gridview in this way(image),how can i perform it,i have no idea,if i have to edit the column or add template fields.,please help.
If we add,a footer,it can be displayed only on the last row,but,how to make it be displayed in the center.
You would be better off using something like a Repeater or DataList control, which give you more control over the output.
<asp:GridView runat="server" ID="gdv" AutoGenerateColumns="false" Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table width="100%">
<tr>
<td>
Exam Date
</td>
<td>
<%#Eval("Exam_Date") %>
</td>
<td>
Section
</td>
<td>
<%#Eval("Section") %>
</td>
</tr>
<tr>
<td>
Total Students
</td>
<td>
<%#Eval("Total_Students") %>
</td>
<td>
No. of students passed
</td>
<td>
<%#Eval("StudentPassed") %>
</td>
</tr>
<tr>
<td colspan="2">
over all pass percentange
</td>
<td colspan="2">
<%#Eval("Overall_Percent") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
On cs page:
gdv.DataSource = YourDataSource;
gdv.DataBind();
I guess you need to do a column spanning to have this look. (I am assuming you have all the data needed to bind to the control.)
You can use Gridview Footer for this display .
<asp:TemplateField>
<FooterTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblname" runat="server" Text="NAME"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtbx" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</FooterTemplate>
</asp:TemplateField>
On RowDataBound Event you can set your total to label .
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = "Total";
}
}

possible give two datasource to one repeater

This is my repeater control with data coming from [Patient_Master] table. But Visit_Date is coming from [Patient_Visit] table. How can I show Visit_Date to the same repeater? Is it possible to give two datasources to one repeater? [Patient_Master] and [Patient_Visit] have a relation:
<asp:Repeater ID="repeaterPatientList" runat="server" OnItemDataBound="repeaterPatientList_ItemDataBound" >
<ItemTemplate>
<tr onclick="selectRow(this);">
<td class="csstablelisttd" style="display:none" >
<asp:Label ID="lblPID" runat="server" Text='<%#Eval("PID")%>'></asp:Label>
</td>
<td class="csstablelisttd" >
<%#Eval("Patient_Name")%>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblPatientName" runat="server" Text='<%#Eval("Patient_ID")%>'></asp:Label>
</td>
<td class="csstablelisttd" >
<asp:Label ID="lblSex" runat="server" Text='<%#Eval("Sex")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblPatientsBirthDate" runat="server" Text='<%#Eval("Patients_Birth_Date")%>'></asp:Label>
</td>
<td class="csstablelisttd">
<asp:Label ID="lblLastVisitDate" runat="server" Text='<%#Eval("Visit_Date")%>'></asp:Label>
</td>
<td class="csstablelisttd">
New
</td>
<td id="tdTodaysVisit" bgcolor="#00cc66" runat="server">
<span class="cssgreen">Today's Visit</span>
</td>
<td class="csstablelisttd">
<%--<asp:HyperLink ID="lnkSchedule" CssClass="csshyperlinkSchedulePatient" runat="server" NavigateUrl='<%# Eval("PID", "~/Create_Order.aspx?ID={0}") %>'>Schedule</asp:HyperLink>--%>
Schedule
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Why don't you use an outer join between patient_master and patient_visit.

Table display issue

I got a table with 2 nested tables inside that display my two repeaters. My repeaters display Home and office addresses respectively. The problem is that whenever I add a new record in one repeater, the other repeater table's display gets messed up. Like if I add a record in rpt1 , then table for rpt1 moves up and table for rpt2 goes down..ie the headers do not display in one single line . They move up and down when records are added or deleted. WHat I want is these headers to be fixed so if I add new records or delete records, the headings of both repeaters display on the same line...How do I fix this ? Hope its not confusing.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<asp:Panel ID="pnlAddAddress" runat="server">
<asp:Repeater ID="rpt1" OnItemCommand="rpt1_ItemCommand" runat="server" OnItemDataBound="rpt1_OnItemDataBound">
<HeaderTemplate>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressB" runat="server" Text='<%# Eval("Address1")%>' CommandName="DisplayAddressB" CommandArgument='<%#Eval("AddID") %>' CausesValidation=false></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<%-- Visible='<%# Eval("IsDefault")%>'--%>
<asp:LinkButton ID="lnkDefaultB" Text="Set as Default" CommandName="SetDefaultB" runat="server" CommandArgument='<%# Eval("AddID") + "," + Eval("IsB") %>'
CausesValidation="false" Visible='<%# Eval("IsDefault")%>'></asp:LinkButton>
<asp:Label ID="labelDefaultB" Text="Yes" runat="server" Visible='<%# Eval("IsDefault")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlSping" runat="server">
<asp:Repeater ID="rpt12" OnItemCommand="rpt12_ItemCommand" runat="server" OnItemDataBound="rptSpping_OnItemDataBound">
<HeaderTemplate>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="linegrey">
</td>
</tr>
<tr class="lgrey">
<td>
Address1
</td>
<td>
City
</td>
<td>
State
</td>
<td>
IsDefault
</td>
<td>
Actions
</td>
</tr>
<tr>
<td colspan="5" class="dots">
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkAddressS" runat="server" Text='<%# Eval("Address1")%>' CommandArgument='<%#Eval("AddID") %>' CommandName="DisplayAddressS" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<%# Eval("City")%>
</td>
<td>
<%# Eval("State")%>
</td>
<td>
<asp:LinkButton ID="lnkDefaultS" Text="Set as Default" CommandName="SetDefaultS" runat="server" Visible=true CommandArgument='<%# Eval("AddID") + "," + Eval("IsS") %>'
CausesValidation="false"></asp:LinkButton>
<asp:Label ID="labelDefaultS" Text="Yes" runat="server" Visible=true></asp:Label>
</td>
<td>
<asp:ImageButton ID="lnkAdd" Text="Edit" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Edit" runat="server" ImageUrl="~/images/Edit.gif" Width="14" Height="14" ToolTip="Edit"></asp:ImageButton>
<asp:ImageButton ID="lnkDel" Text="Delete" CommandArgument='<%#Eval("AddID") %>'
CausesValidation="false" CommandName="Delete" runat="server" ImageUrl="~/images/Delete.gif" Width="14" Height="14" ToolTip="Delete"></asp:ImageButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</td>
</tr>
</table>
Use css attribute valign and set its value to top like this <td width="50%" valign="top">.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" valign="top">
<asp:Panel ID="pnlAddAddress" runat="server">
......
</asp:Panel>
</td>
<td valign="top">
<asp:Panel ID="pnlSping" runat="server">
......
</asp:Panel>
</td>
</tr>
</table>
For headers look to use the <th> element, this will keep them at the top of the table.
Put the <table> tags you do have outside your repeater controls, make sure the repeater only renders a single row and the same for the header.
Unless you have good reason consider just wrapping the two tables in <div> tags as nested tables really don't work ideally for layout.

Categories