在Gridview中以不同方式对齐文本和值 [英] Aligning text and values differently in Gridview

查看:69
本文介绍了在Gridview中以不同方式对齐文本和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LINQ我创建了以下查询:



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 />



在我的gridview中,我想将左边的文本字段和右边的值字段对齐。这是我目前的gridview代码:




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"

        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>

推荐答案

您的选择代码显然无关紧要。您的数据来源无关紧要。你似乎让gridview只显示它自动给出的所有内容。如果要控制到单个单元格上的设置对齐点,则需要编写一个列出要显示的元素的模板。
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.


这篇关于在Gridview中以不同方式对齐文本和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆