我有一个sqldatasource,显示在网格视图中。基本上我所做的就是使用gridview并将其转换为数据集以导出到XML文件。问题是正在创建XML文件(当按下我在aspx页面中的报告按钮时),其中包含列,但列的值未显示。任何人都可以帮我解决这个问题吗?
bellow是按下报告按钮(Sample2.xml)时生成的XML文件:
<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="DefaultView" msdata:CaseSensitive="False" msdata:Locale="en-US">
<xs:complexType>
<xs:sequence>
<xs:element name="USERID" type="xs:int" minOccurs="0" />
<xs:element name="NAME" type="xs:string" minOccurs="0" />
<xs:element name="TITLE" type="xs:string" minOccurs="0" />
<xs:element name="CHECKTIME" type="xs:dateTime" minOccurs="0" />
<xs:element name="CHECKTYPE" type="xs:string" minOccurs="0" />
<xs:element name="trans" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
aspx页面的C#代码:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace TimeClockViewer
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
protected void btnReport_Click(object sender, EventArgs e)
{
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = (DataView)SqlDataSource1.Select(args);
DataTable table = view.ToTable();
DataSet ds = new DataSet();
ds.Tables.Add(table);
ds.WriteXmlSchema("Sample2.xml");
}
}
}
aspx页面代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="TimeClockManager.aspx.cs" Inherits="TimeClockViewer.WebForm1" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:attConnectionString %>" SelectCommand="SELECT USERINFO.USERID, USERINFO.NAME, USERINFO.TITLE, CHECKINOUT.CHECKTIME, CHECKINOUT.CHECKTYPE, CHECKINOUT.trans FROM USERINFO INNER JOIN CHECKINOUT ON USERINFO.USERID = CHECKINOUT.USERID WHERE (USERINFO.NAME = @NAME) AND (@NAME <> '-1') AND (CHECKINOUT.CHECKTIME BETWEEN @startDate AND @endDate + ' 23:59:00.000') OR (@NAME = '-1') AND (CHECKINOUT.CHECKTIME BETWEEN @startDate AND @endDate + ' 23:59:00.000') AND (1 = 1)" UpdateCommand="UPDATE CHECKINOUT SET CHECKTYPE = @CHECKTYPE, CHECKTIME = @CHECKTIME FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID = USERINFO.USERID WHERE (CHECKINOUT.trans = @trans) AND (CHECKINOUT.USERID = @USERID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlEmployee" Name="NAME" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="txtBoxStartDate" Name="startDate" PropertyName="Text" />
<asp:ControlParameter ControlID="txtBoxEndDate" Name="endDate" PropertyName="Text" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="CHECKTYPE" />
<asp:Parameter Name="CHECKTIME" />
<asp:Parameter Name="trans" />
<asp:Parameter Name="USERID" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:attConnectionString %>" SelectCommand="SELECT [NAME] FROM [USERINFO] ORDER BY [NAME]"></asp:SqlDataSource>
Employee:
<asp:DropDownList ID="ddlEmployee" runat="server" DataSourceID="SqlDataSource2" DataTextField="NAME" DataValueField="NAME" Height="40px" Width="193px" AppendDataBoundItems="True">
<asp:ListItem Value="-1">All</asp:ListItem>
</asp:DropDownList>
Start Date:
<asp:TextBox ID="txtBoxStartDate" runat="server" Width="146px"></asp:TextBox>
End Date<ajaxToolkit:CalendarExtender ID="txtBoxStartDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtBoxStartDate">
</ajaxToolkit:CalendarExtender>
:
<asp:TextBox ID="txtBoxEndDate" runat="server" Width="146px"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="txtBoxEndDate_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtBoxEndDate">
</ajaxToolkit:CalendarExtender>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="USERID,trans" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="USERID" HeaderText="USERID" InsertVisible="False" ReadOnly="True" SortExpression="USERID" />
<asp:BoundField DataField="NAME" HeaderText="NAME" ReadOnly="True" SortExpression="NAME" />
<asp:BoundField DataField="TITLE" HeaderText="TITLE" ReadOnly="True" SortExpression="TITLE" />
<asp:BoundField DataField="CHECKTIME" HeaderText="CHECKTIME" SortExpression="CHECKTIME" />
<asp:BoundField DataField="CHECKTYPE" HeaderText="CHECKTYPE" SortExpression="CHECKTYPE" />
<asp:BoundField DataField="trans" HeaderText="Transaction" InsertVisible="False" ReadOnly="True" SortExpression="trans" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnReport" runat="server" OnClick="btnReport_Click" Text="Reports" />
<br />
<br />
<br />
<br />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="1202px" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1104px" />
<br />
<br />
<br />
<br />
</asp:Content>