Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Make GridView display data horizontaly instead of vertically

Posted on 2008-10-01
8
Medium Priority
?
1,026 Views
Last Modified: 2013-11-26
Hi,

I want to make a GridView display data horizontaly instead of vertically. Normally if the column names are is what the header should be it would be right as it is, but in my case the column names is in one table and the values in another table.

I've attached a image that shows how I want it to be displayed and how it looks like now, and also the structure of the tables in the Database.

The SQL Query looks like this:

---------------------------------------------------------

SELECT p.name, a.val

FROM [ARTIKEL_Details] a

LEFT OUTER JOIN ARTIKEL_Fields p

ON a.id_field = p.id_field

WHERE a.ARTNR = @ArtGet

---------------------------------------------------------

I have a queryString from that's linked from another page with the Article number like this:

- article.aspx?artnr=[ArticleNumber]

Have attached the code to the page so you could look on.

So, is there a way of doing this with the grid view or any other way?

The reason I want to do it this way is becouse the table with the column names (ARTIKEL_Field) have about 480 values, and having all values doesn't have a value in ARTIKEL_Details.

And a table with 480 Columns wouldn't be any good at all.

Hope you getting the idea of what I'm trying to do and please ask if there's any questions.

// Tobias
//article.aspx
 
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="article.aspx.cs" Inherits="article" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
    .style1
    {
        text-decoration: underline;
    }
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentHolder" Runat="Server">
    <p>
        <span class="style1">Visar Artikel</span><b>
        <asp:Label ID="ArticleLabel" runat="server" Text="[Artnr]"></asp:Label>
        </b>
     </p>
    <p>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" DataSourceID="ViewArticle" ForeColor="#333333" 
            GridLines="None" AllowSorting="True">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="name" HeaderText="Fält" SortExpression="name" >
                <ControlStyle Font-Bold="True" />
                <ItemStyle Font-Bold="True" HorizontalAlign="Right" />
                </asp:BoundField>
                <asp:BoundField DataField="val" HeaderText="Värde" SortExpression="val" />
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <asp:SqlDataSource ID="ViewArticle" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DuellsCM5ConnectionString %>" SelectCommand="SELECT p.name, a.val 
 
FROM [ARTIKEL_Details] a 
 
LEFT OUTER JOIN ARTIKEL_Fields p
 
ON a.id_field = p.id_field
 
WHERE a.ARTNR = @ArtGet">
            <SelectParameters>
                <asp:QueryStringParameter ConvertEmptyStringToNull="False" Name="ArtGet" 
                    QueryStringField="artnr" Size="50" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    </p>
</asp:Content>
 
//article.aspx.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class article : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String artnr = Request.QueryString["artnr"].ToString();
        ArticleLabel.Text = artnr;
    }
}

Open in new window

gridView.jpg
0
Comment
Question by:Gudorian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22612415
not sure if this is going to help you but have you tried detailsview?
0
 
LVL 2

Author Comment

by:Gudorian
ID: 22612445
Did test it out, the problem there was it put the data Like this

----------------------------------------------------
              Fält | Benämning ESS  
----------------------------------------------------
Beskrivning | Handtag ATV gummi svart/grå
----------------------------------------------------

Only one value was shown in the results.
0
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 2000 total points
ID: 22612482
check out  DataList control which has RepeatColumn and RepeatDirection properties:
You can specify the RepeatDirection which equals Vertical/Horizontal

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/datalist.aspx
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:informaniac
ID: 22612556
SQL Reporting might help, but that's a long shot...

0
 
LVL 2

Author Comment

by:Gudorian
ID: 22612567
It says there you could use "RepeatDirection" and "RepeatColumns", but I don't get how to apply it to the DataView.

Is it also possible to make the data From the "ARTIKEL_Field" table to be show at the top

and then add multiple rows from "ARTIKEL_Details" beneth it?

I may have to do this later.
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22612615
check out  DataList control which has RepeatColumn and RepeatDirection properties
you will not find it in dataview.
0
 
LVL 2

Author Comment

by:Gudorian
ID: 22612640
Ah, I got it, was trying to apply it on a DetailsView. Thanks for the help
0
 
LVL 2

Author Closing Comment

by:Gudorian
ID: 31501876
thx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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