<asp:GridView ID="gvInfo" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" AutoGenerateColumns="False" DataKeyNames="lblUserID" OnRowDataBound="gvInfo_RowDataBound" OnRowDeleting="gvInfo_RowDeleting" OnRowEditing="gvInfo_RowEditing">
                    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                    <Columns>
                        <asp:TemplateField HeaderText="用户编号">
                            <ItemStyle Width="250px" HorizontalAlign="Left" />
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblUserID" Text = ""></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="用户名称">
                            <ItemStyle Width="250px" HorizontalAlign="Center" />
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblUserName" Text=""></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField DeleteText="删除" ShowDeleteButton="True">
                            <ItemStyle HorizontalAlign="Center" Width="40px" />
                        </asp:CommandField>
                    </Columns>
                    <AlternatingRowStyle BackColor="Gainsboro" />
                </asp:GridView>

解决方案 »

  1.   

    <asp:TemplateField HeaderText="用户编号">
     <ItemStyle Width="250px" HorizontalAlign="Left" />
    <ItemTemplate>
     <asp:Label runat="server" ID="lblUserID" Text = '<%# Eval("字段名") %>'></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    所有的绑定需要用Eval来进行
    参数为你在datasource里面查询得到的字段名
      

  2.   

    不要用Label,这么多label降低服务器效率
    直接绑就可以了
    <asp:TemplateField HeaderText="用户编号">
     <ItemStyle Width="250px" HorizontalAlign="Left" />
    <ItemTemplate>
    <div><%# Eval("字段名") %>
    </div>    </ItemTemplate>
    </asp:TemplateField>
      

  3.   

    最好是用:
    <asp:TemplateField HeaderText="用户编号">
     <ItemStyle Width="250px" HorizontalAlign="Left" />
    <ItemTemplate>
    <div><%# DataBinder.Eval(DataItem,"字段名") %>
    </div>    </ItemTemplate>
    </asp:TemplateField>