Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

XML
<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"
        onselectedindexchanged="GridView1_SelectedIndexChanged1">
        <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" />
    </asp:GridView>
Posted
Updated 1-Jan-13 10:53am
v3
Comments
[no name] 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

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.
 
Share this answer
 
Comments
MrSME 1-Jan-13 17:01pm    
I am very new to ASP.net 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900