How to show repeater dynamically?

techques
techques used Ask the Experts™
on
I have a repeater to display data in aspx page with C#.

In C#,
protected void Page_Load(object sender, EventArgs e)
{
Bind_Client_Transaction(clientid, System.DateTime.Now.ToString("yyyy-MM-dd"), System.DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"), "USD");
}

It can show transactions for one currency of a client in a particular day.

Now, I need to show multi currencies for a client.

I use

SELECT currency FROM [alltransaction] where clientid=153 group by currency

to find out which currency that the client has transactions.

It shows

AUD
CNY TT
EUR
HKD
USD

It means this client has transacted 5 currencies.

Since there is only one repeater in a aspx page, but the numbers of currencies are dynamic.

How should I code it?

<asp:Repeater ID="RepeaterUse" runat="server" >
    <ItemTemplate >
        <tr>
        <td><asp:Label ID="id" runat="server" Text ='<%# DataBinder.Eval(Container.DataItem, "id")%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="trandatetime" runat="server" Text ='<%# DataBinder.Eval(Container.DataItem, "trandatetime")%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td><asp:Label ID="type" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "type")%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td><asp:Label ID="currency" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "currency") %>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="rate" runat="server" Text='<%# string.Format("{0:#,##0.0000}",DataBinder.Eval(Container.DataItem, "rate"))%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="amount" runat="server" Text='<%# string.Format("{0:#,##0.00}",DataBinder.Eval(Container.DataItem, "amount"))%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="countervalue" runat="server" Text='<%# string.Format("{0:#,##0.00}",DataBinder.Eval(Container.DataItem, "countervalue"))%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="handlingincome" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "handlingincome") %>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="handlingexpense" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "handlingexpense") %>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="dr" runat="server" Text='<%# string.Format("{0:#,##0.00}",DataBinder.Eval(Container.DataItem, "DR"))%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="cr" runat="server" Text='<%# string.Format("{0:#,##0.00}",DataBinder.Eval(Container.DataItem, "CR"))%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="balance" runat="server" Text='<%# string.Format("{0:#,##0.00}",DataBinder.Eval(Container.DataItem, "Balance"))%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="clientreference" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "clientreference")%>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="remarks" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "remarks") %>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="ashortcode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ashortcode") %>'></asp:Label></td>
        <td>&nbsp;&nbsp;</td>
        <td nowrap><asp:Label ID="status" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "status") %>'></asp:Label></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate ></table></FooterTemplate>
    <HeaderTemplate>
        <table align=left border=1>
            <tr>
            <td align="center">ID</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Date</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Type</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Currency</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Rate</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Amount</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Counter Value</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Income(Fee)</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Expense</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">DR</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">CR</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Balance</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Client Reference</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Remarks</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Location</td>
            <td>&nbsp;&nbsp;</td>
            <td align="center">Status</td>
            </tr>
    </HeaderTemplate>
</asp:Repeater>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013
Commented:
sorry so what exactly you want to do?
I see a label:
 <td><asp:Label ID="currency" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "currency") %>'></asp:Label></td>

but then I did not get exactly what you want...
To deal with each item individually....you should use ItemDataBound event of the Repeater control.
You can format each item inside that even accordingly as per your requirement, depending on the data bound to that item.

Author

Commented:
Since each client has different currencies options,

client A has
AUD, EUR, HKD, USD

client B has
GBP, USD, JPY

The sql can accept one currency to sort out the result.

However, the repeater just shows one currency because of the query.

There are 30 currencies in total, but only those have transactions for a client will display.

I am thinking do I need to use 30 panels in aspx. If the currency has transaction, then display the panel. Otherwise, hidden that panel.

Or, should I modify the query in order to sort that result with multi-currencies?

 

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial