1

我设置了一个 Sqldatasource 和一个 Gridview:

        <asp:SqlDataSource ID="DetailsSQLDataSource" runat="server"  ConnectionString="<%$ ConnectionStrings:aspnet-WebApplication6-20131007103938ConnectionString1 %>" 
    SelectCommand="SELECT [ProjectID], [ProjectName], [CreatorID], [Deadline] FROM [tProject] WHERE 1=1"
    >   
       <SelectParameters>
         <asp:Parameter Type="String" Name="ProjectID"></asp:Parameter>
       </SelectParameters>
    </asp:SqlDataSource>


<asp:GridView ID="GridView1" runat="server" DataSourceID="DetailsSQLDataSource" AutoGenerateColumns="False" DataKeyNames="ProjectID" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating">
    <Columns>
        <asp:BoundField DataField="ProjectID" HeaderText="ProjectID" ReadOnly="True" SortExpression="ProjectID"></asp:BoundField>
        <asp:BoundField DataField="ProjectName" HeaderText="ProjectName" SortExpression="ProjectName"></asp:BoundField>
        <asp:BoundField DataField="CreatorID" HeaderText="CreatorID" SortExpression="CreatorID"></asp:BoundField>
        <asp:BoundField DataField="Deadline" HeaderText="Deadline" SortExpression="Deadline"></asp:BoundField>
    </Columns>
</asp:GridView>

我已经测试了 selectcommand,它返回一个有 4 行的表。然而,gridview 中没有可显示的数据。代码隐藏几乎是空的,肯定不会影响这些控件。可能与连接有关吗?我该如何测试呢?

4

1 回答 1

0

调用.DataBind()以实际强制将数据绑定到网格,如下所示:

GridView1.DataBind();  
于 2013-10-31T14:45:38.610 回答