开发者

fixing column data type and duplicate column problem

开发者 https://www.devze.com 2023-01-27 11:34 出处:网络
This is my programs complete code, the only problem is i want to fix the amount of decimal places that show up in my gridview. The problem is if i do this on the asp side the location of the column ge

This is my programs complete code, the only problem is i want to fix the amount of decimal places that show up in my gridview. The problem is if i do this on the asp side the location of the column gets thrown off and the column is duplicated. I figured if i just remade the table on the asp side it would work only problem is if i remove the sql for that particular column the asp side column cannot get data.

 Imports System.Data.Sql
    Imports System.Data.SqlClient
    Imports System.Data
    Partial Class _Default
        Inherits System.Web.UI.Page
        Public saocmd As New SqlCommand()
        Public saoda As New SqlDataAdapter(saocmd)

        Dim saods As New DataSet

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            saocmd.Connection = conn
            conn.Open()

            Dim ds As New DataSet

            saocmd.CommandText = "SELECT B603SalesAsOFMASTER.SDESCR, B603SalesAsOFMASTER.DYYYY, B603SalesAsOFMASTER.AsOFSales, B603SalesAsOFMASTER.ASOFPAX, B603SalesAsOFMASTER.YESales, B603SalesAsOFMASTER.YEPAX, B603SalesAsOFMASTER.PCTofSales, B601SalesAsOF.Sales AS [Current Sales], B601SalesAsOF.PAX AS [Current PAX] FROM B603SalesAsOFMASTER INNER JOIN B601SalesAsOF ON B603SalesAsOFMASTER.SDESCR = B601SalesAsOF.SDESCR WHERE (B603SalesAsOFMASTER.DYYYY = '2008') AND (B601SalesAsOF.DYYYY = '2010')"
            saoda.Fill(saods, "salesasoftable")

开发者_StackOverflow            Dim pctofpax As New DataColumn
            pctofpax = New DataColumn("PCTPAX1", GetType(Decimal))
            pctofpax.Expression = "[ASOFPAX] / [YEPAX]"
            saods.Tables("salesasoftable").Columns.Add(pctofpax)

            Dim avgppax As New DataColumn
            avgppax = New DataColumn("AVG PAX", GetType(Double))
            avgppax.Expression = "[Current Sales] / [Current PAX]"
            saods.Tables("salesasoftable").Columns.Add(avgppax)

            Dim projectedye As New DataColumn
            projectedye = New DataColumn("Projected YE Sales", GetType(Double))
            projectedye.Expression = "[Current Sales] / PCTofSales"
            saods.Tables("salesasoftable").Columns.Add(projectedye)

            Dim projectedyep As New DataColumn
            projectedyep = New DataColumn("Projected YE PAX", GetType(Double))
            projectedyep.Expression = "[Current PAX] / PCTPAX1"
            saods.Tables("salesasoftable").Columns.Add(projectedyep)



            GridView1.DataSource = saods

            GridView1.DataBind()

            saoda.FillSchema(saods, SchemaType.Mapped)

            conn.Close()
        End Sub
    End Class

ASP Side



     <%@ 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>

            <span lang="en-us">Sales As Of Analysis</span><br />
           <asp:GridView ID="GridView1" runat="server" BackColor="White" 
                  BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
                  GridLines="Vertical">
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
             <asp:Boundfield DataField="SDESCR" 
                             HeaderText="Regions">
             </asp:Boundfield>

             <asp:Boundfield DataField="DYYYY" 
                             HeaderText="DYYYY">
             </asp:Boundfield>


            <asp:Boundfield DataField="asofsales" 
                             HeaderText="As Of Sales" 
                             DataFormatString="{0:c}">
            </asp:Boundfield>
        </Columns>
    </asp:GridView>

        </div>
        </form>
    </body>
    </html>


the answer was to turn off autogenerate columns!

0

精彩评论

暂无评论...
验证码 换一张
取 消