[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to get repeater to display 2 rows for each record

Posted on 2012-09-06
4
Medium Priority
?
513 Views
Last Modified: 2012-09-07
Hi!

I need to display data like attached picture.1 record to rows
My code looks like this until now. Lets say I want to get the headers POANG and PERIOD for one record on a second row. How do I do it?


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        Skriv namnet/en del av namnet av den kurs du söker efter<br /> <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Visa kurser" />
    
    </div>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString56 %>" 
        
        
        SelectCommand="select * FROM [KJ1].[KJ1].[KJGV1VUT] WHERE ([KURSNAMN] LIKE '%' + @KURSNAMN + '%')">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="KURSNAMN" 
                PropertyName="Text" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:Repeater ID="Repeater1" runat="server" 

        DataSourceID="SqlDataSource2">
         <HeaderTemplate>
         <table border="1" width="100%">

          <table>
            <tr>
              <th>
                Kursnamn</th>
              <th>
                Kurskod</th>
                <th>
                Period</th>
                <th>
                Poäng</th>
                <th>
                Skolnamn</th>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>
          <tr>
            <td>
              <asp:Label runat="server" ID="Label1" Text='<%# Eval("KURSNAMN") %>' />
            </td>
            <td >
              <asp:Label runat="server" ID="Label2" Text='<%# Eval("KURSKOD") %>' />
            </td>
            <td>
              <asp:Label runat="server" ID="Label3" Text='<%# Eval("PERIOD") %>' />
            </td>
            <td>
              <asp:Label runat="server" ID="Label4" Text='<%# Eval("POANG") %>' />
            </td>
            <td>
              <asp:Label runat="server" ID="Label5" Text='<%# Eval("SKOLNAMN") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
<tr bgcolor="#e8e8e8">
   </td>
            <td >
              <asp:Label runat="server" ID="Label2" Text='<%# Eval("KURSKOD") %>' />
            </td>
            <td>
              <asp:Label runat="server" ID="Label3" Text='<%# Eval("PERIOD") %>' />
            </td>
            <td>
              <asp:Label runat="server" ID="Label4" Text='<%# Eval("POANG") %>' />
            </td>
</tr>
</AlternatingItemTemplate>


        
        
        
        
        
        <SeparatorTemplate>
<tr>
<td colspan="6"><hr /></td>
</tr>
</SeparatorTemplate>


        
        
        
        
    </asp:Repeater>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:marcgu
  • 2
4 Comments
 
LVL 14

Expert Comment

by:dejaanbu
ID: 38375399
can u elaborate ur requirement?

what is the need for displaying same row twice inside repeater?
0
 

Author Comment

by:marcgu
ID: 38375693
Hi!

Of course. First it´s not neccessary to use a repeater. Datalist or something else would also be possible. I thought that a repater would be the best, but I may be wrong.

Lets say, In my view in the database I have the following fields: coursenamne, courseid, credits, unit, daytimecourse, period. (in reality they are called something else)

I am building a website where a user can search for a course by entering the course name in a text box.

The result should for each record should be:

coursename, courseid, credit
unit, daytimecourse, period

coursenamne, courseid, credit
unit, daytimecourse, period

and so on....

Now I get:
coursename, courseid, credit, unit, daytimecourse, period

coursename, courseid, credit, unit, daytimecourse, period

and so on.

The problem: I do not want the user to be forced to a lot of horizontal scrolling. Therefore I want, just like the picture I added, each record on 2 rows.

I hope this is more clear.
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 2000 total points
ID: 38375817
Hi marcgu,

You could create an item template with a table in it, display the first 3 fields (coursename, courseid, credit) in the first row of the table and the second 3 fields (unit, daytimecourse, period) in the second row of the item template.

If you want separate headers, create a four row table in the itemtemplate, two styled as headers with the header text you want to display for each.

Possibly a datalist would do the trick.

Alan
0
 

Author Closing Comment

by:marcgu
ID: 38376605
Perfect.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question