Inserting Table on the ASPX File

I am trying to display a customer’s statement of account. Unfortunately, the table always appear on the top of header of my page. I display the table through the code behind file of my page. Can anyone give me an idea. Attach is the modified image of table that displays on the top of my header.

Sounds like you have a HTML or CSS issue of some sort. Impossible to tell without some code to review though.

Oh dear, you’re not doing something like the following are you?

void Page_Load(object s, EventArgs e) {
    var data = GetSomeData();

    Response.Write("<table yada yada>");
    foreach(var whatever in data) {
        Response.Write("rows and columns here");


If the answer is yes, you’re going about it completely the wrong way. You should be using the databinding functionality of the various server controls.
If the answer is no then we need to see some code.

That’s the first thing I thought, too. Response.Write just sticks stuff at the top.

Oh ok, well I see people already came to the same conclusion as I did in your other thread. Check my comment in your previous thread. I am not going to re-post it here. Hope it helps

Why he not listen to you?

I am actually using a response.write method to display my table. Through the use of a table, I can easily categorize customer’s account either debit or credit.

Yeah, we know. Don’t do that.

In line with your recommendation, I used a repeater. But then, I am searching the web for 2hours and yet I cannot find a discussion on how am I be able to use an IF statement inside my repeater. I used an IF statement but it resulted to an error like Container does not exists in the current context. Can you anyone help me please.

My guess would be to use the repeater’s onDataBind attribute to get a RepeaterItemEventArg.

I think you are approaching this the wrong way. On your front end you want a repeater and in the cs page have a List<T> or something that you bind to it. Post some code and we can see where u are going wrong. According to your screenshot above, there looks as if there is no need for any if statements. As if statements are nto allowed inside repeaters

That’s a much better plan. I think OP needs to get a book on the basics. It’ll save a whole lot of headaches.

<asp:Repeater ID="rptBill" runat="server" DataSourceID="dtBill">
                                    <td>Entry Code</td><td>Description</td><td>Debit</td><td>Credit</td>
                                <td><&#37;#DataBinder.Eval(Container.DataItem, "Code")%></td>
                                <td><%#DataBinder.Eval(Container.DataItem, "Description")%></td>
                                <td><%#DataBinder.Eval(Container.DataItem, "Amount")%></td>

                    <asp:SqlDataSource ID="dtBill" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT servicecode AS Code, description AS Description, amount as Amount, 'DEBIT' AS category FROM fees">

The code above illustrate how I display the customer’s billing statement. For the mean time, I only retrieve accounts that is categorized AS DEBIT. In my code, I haven’t use any IF statement, but I think I have to, because I have to separate DEBIT accounts from CREDIT accounts. Can anyone help me.

Don’t use the SqlDataSource in the .aspx file. Define the DataSource for the repeater in the code behind instead.

I’ll work up an example in Linq to Sql and show you. Hold please.

OK, say I have a list of tips I want to show on a page. I put my [tip] table in my Linq To Sql class. Then I add my Repeater (we’ll call it tipsList):

<asp:repeater id="tipsList" runat="server">
		<li><&#37;#Eval("tipsText") %></li>

and then I set the data source like this:

	using (var tdc = new siteDataContext())
		var tips = from t in
		    select new
					tipsText = t.tipsText
		tipsList.DataSource = tips;

Hi imaginekitty is the example above is LINQ?

It is Linq but that’s not important, it shows how to databind an object to the repeater in the code behind.

@imaginekitty…I already bind my repeater in the code behind. But I still do have a problem. I haven’t separate yet, the debit accounts from credit accounts. Since, one of the members mentioned that I cannot use an IF statement, then, what strategy will I employ in order for me to resolve this problem. If I cannot separate the debit accounts from credit accounts, all I have to do is to change the font color of the credit accounts in to RED, but I guess, I still need the power of IF statement.

You can either do it in the codebehind or in the repeater. Hold on. I’ll work something up.

Is this more of what you’re looking for?

		<asp:repeater id="creditList" runat="server">
						<td>Entry Code</td>
					<td<%#String.Format("{0}", Eval("Category") == "Credit" ? " style=\\"color:#f00;\\"" : String.Empty) %>><%#String.Format("{0:c}",Eval("Amount"))%></td>
using System;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page 
	public class statement
		public string Code { get; set; }
		public string Description { get; set; }
		public double Amount { get; set; }
		public string Category { get; set; }
    protected void Page_Load(object sender, EventArgs e)
		List<statement> theList = new List<statement>();
		theList.Add(new statement { Code = "A01", Description = "pwnd", Amount = 10.40, Category = "Debit" });
		theList.Add(new statement { Code = "A02", Description = "evil", Amount = 110.00, Category = "Debit" });
		theList.Add(new statement { Code = "A03", Description = "fault", Amount = 140.89, Category = "Credit" });
		theList.Add(new statement { Code = "D01", Description = "macreme", Amount = 40.02, Category = "Debit" });
		creditList.DataSource = theList;