Click here to Skip to main content
13,295,051 members (85,084 online)
Rate this:
Please Sign up or sign in to vote.
Using LINQ I created the following query:

using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
<br />
public partial class Results_Standings : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
        DataClasses2DataContext db = new DataClasses2DataContext();<br />
<br />
        var Standings = from p in db.Pit_Outputs<br />
                         where p.Season  == "2011"<br />
                         group p by p.Team_ID into g<br />
                         orderby g.Sum(w => w.W) descending<br />
                         <br />
                         select new <br />
                         {<br />
                             Team = g.First().Teams.Team_City,<br />
                             W = g.Sum(w => w.W),<br />
                             L = g.Sum(l=> l.L),<br />
                             P = g.Sum(w => w.W) / (g.Sum(w => w.W) + g.Sum(l => l.L)),<br />
                         };<br />
        GridView1.DataSource = Standings;<br />
        <br />
        GridView1.DataBind();<br />
    }<br />
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)<br />
    {<br />
<br />
    }<br />
    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)<br />
    {<br />
<br />
    }<br />
}<br />

In my gridview I want to align the text fields left and the value fields right. Here is my current gridview code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AllowSorting="True" CellPadding="4" EnableSortingAndPagingCallbacks="True"
        ForeColor="#333333" GridLines="None" PageSize="30"
        HorizontalAlign="Center" style="text-align: right"
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
Posted 1-Jan-13 5:23am
Updated 1-Jan-13 11:53am
Sheikh Muhammad Haris 1-Jan-13 13:23pm
What do you mean by Text Fields and Value Fields ? You haven't mention the fields to bind with your GridView
MrSME 1-Jan-13 17:04pm
My LINQ to SQL query is bound to the gridview. Team is a text column and the other fields are numeric. Thanks.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your select code is obviously irrelevant. Where your data comes from does not matter. You seem to be letting the gridview just display everything it's given automatically. You will need to write a template that lists the elements to display, if you want to take control to the point of setting alignment on individual cells.
MrSME 1-Jan-13 17:01pm
I am very new to so not much is obvious to me. Is writing a template something that I do instead of using a gridview or something that I do with my gridview. Do you have any recommended links to learn how to do this or should I search this sight? Thanks.
Christian Graus 1-Jan-13 17:14pm
If you read the MSDN documentation and this site, you should find the info you need. You should not be trying to do all of this without having a clue on these most basic things, however.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100