1
<div style="width:100%; height:200px; overflow:scroll; border-color:White;">
        <asp:GridView ID="UsersGridView" runat="server" 
            CssClass="label" ShowHeaderWhenEmpty="True" Width="100%" 
            AllowSorting="True" HeaderStyle-BackColor="LightGray" CellPadding="4" 
            ForeColor="#333333" GridLines="None" DataSourceID="UsersDataSource" >
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField HeaderText="Fleet Description" ReadOnly="True" 
                    HeaderStyle-Wrap="false" HtmlEncode="True" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Fleet Code" HeaderText="Fleet Code" ReadOnly="True" 
                    HeaderStyle-Wrap="false" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
                <asp:BoundField DataField="First Name" HeaderText="First Name" ReadOnly="True" 
                    HeaderStyle-Wrap="false" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Last Name" HeaderText="Last Name" ReadOnly="True" 
                    HeaderStyle-Wrap="false" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Username" HeaderText="User Name" ReadOnly="True" 
                    HeaderStyle-Wrap="false" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True" 
                    HeaderStyle-Wrap="false" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Phone" HeaderText="Phone" ReadOnly="True" 
                    HeaderStyle-Wrap="false" >
                    <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundField>
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>
        <asp:SqlDataSource ID="UsersDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
            SelectCommand="SELECT        UserDataAssociation.Fleet as &quot;Fleet Code&quot;, UserDataAssociation.FirstName as &quot;First Name&quot;, UserDataAssociation.LastName as &quot;Last Name&quot;, aspnet_Users.UserName, aspnet_Membership.Email, 
                     UserDataAssociation.Phone
FROM            aspnet_Membership INNER JOIN
                     aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId INNER JOIN
                     UserDataAssociation ON aspnet_Membership.UserId = UserDataAssociation.UserId"></asp:SqlDataSource>
    </div>

我有一个带有select语句的sqldatasource的gridview。但是,当页面加载时,gridview 的原始列增加了一倍,由数据源创建。我希望情况显然不是这样。

我究竟做错了什么?

谢谢

4

2 回答 2

5

Gridview AutoGenerateColumns属性设置为 False

于 2012-07-04T08:24:04.890 回答
3

在编辑列菜单中有一个“自动生成字段”选项,取消选中它。当您选择 SqlDataSource 作为数据源时,它创建了列,并且由于某种原因它没有取消选中自动生成字段选项,这就是它创建两次的原因。单击网格视图时,右上角会有一个白色小箭头,提供更多选项,如果您展开该菜单,单击“编辑列”,然后您可以取消选中“自动生成字段”选项。或者只是将AutoGenerateColumns属性设置为false

在此处输入图像描述

于 2012-07-04T08:24:02.490 回答