我放到页面上一个gridview控件,数据源也配置好了,但是却没有显示出来,我也不知道是哪里错了。
页面代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="aeid" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" style="margin-right: 25px"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:DynamicField DataField="stdXh" HeaderText="学号" /> <asp:DynamicField DataField="aeKcmc" HeaderText="课程名称" /> <asp:DynamicField DataField="aeKssj" DataFormatString="{0:yyyy-MM-dd}" HeaderText="考试时间" /> <asp:DynamicField DataField="aeKscs" HeaderText="考试次数" /> <asp:DynamicField DataField="aeKscj" HeaderText="考试成绩" /> <asp:DynamicField DataField="aeid" HeaderText="考号" /> </Columns> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <SortedAscendingCellStyle BackColor="#FDF5AC" /> <SortedAscendingHeaderStyle BackColor="#4D0000" /> <SortedDescendingCellStyle BackColor="#FCF6C0" /> <SortedDescendingHeaderStyle BackColor="#820000" /> </asp:GridView>
web.config
<?xml version="1.0"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> </assemblies> </compilation> <httpRuntime targetFramework="4.5"/> </system.web> <connectionStrings> <add name="stuInfoConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\stuInfo.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/> </connectionStrings> <appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/> </appSettings> </configuration>
gridview控件中datasourceid的用法:
<asp:SqlDataSource ID="sourceProducts" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind %>" ProviderName="System.Data.SqlClient" SelectCommand="select ProductID,ProductName,UnitPrice,UnitsInStock from Products"></asp:SqlDataSource>
<asp:GridView ID="gridProducts" runat="server" DataSourceID="sourceProducts" AllowPaging="true" ShowFooter="true" OnDataBound="gridProducts_DataBound">
</asp:GridView>