2

实际上,说问题可能是错误的。我有 2 页。我可以从第一页获取第二页的查询字符串。这个查询字符串是我查询的关键部分。在调试模式下,我可以看到查询结果,它们就是我想要的。但它不能显示在我的网格视图上。这是我的代码块:我的 CustomerList 页面,

public partial class CustomerList : System.Web.UI.Page
    {
        CustomerBusiness m_CustomerBusiness = new CustomerBusiness();
        COMPANY m_Company = new COMPANY();

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    BindCustomers();
                }
            }

        private void BindCustomers()
                {
                    string CompanyName = Request.QueryString.Get("CompanyName");

                    LabelCompanyName.Text = CompanyName;
                    List<CUSTOMER> CustomerListt = m_CustomerBusiness.SelectByFirmName(CompanyName);
                    GridViewCustomerList.DataSource = CustomerListt;
                    GridViewCustomerList.DataBind();
                }
}

GridView 客户列表:

 <asp:GridView ID="GridViewCustomerList" runat="server" 
            AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 
            BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" 
            ondatabinding="GridViewCustomerList_DataBinding" 
            onselectedindexchanged="GridViewCustomerList_SelectedIndexChanged" 
            Width="239px">
            <AlternatingRowStyle BackColor="#DCDCDC" />
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#0000A9" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#000065" />
        </asp:GridView>

CustomerList 是我想要的,但我的绑定部分不起作用,我在运行项目时看不到 GridViewCustomerList。我研究了一些asp.net页面生命周期模型,目标解决方案可能与此有关。

4

1 回答 1

3

这里的问题是您的标记中没有明确<Column>的声明,并且您将AutoGenerateColumns属性设置为“false”。因此,即使数据绑定到您的 GridView 控件,它也不知道要显示什么(因此它什么也不显示。

这里最简单的解决方案是AutoGenerateColumns="False"从您的 GridView 声明中删除(默认情况下为“true”),您应该一切顺利。它将根据您的数据源自动创建您的列。

或者,您可以通过将列部分添加到 GridView 来指定所需的列。

    <columns>
      <asp:boundfield datafield="columnOne" headertext="Column 1"/>
      <asp:boundfield datafield="columnTwo" headertext="Column 2"/>
      <asp:boundfield datafield="columnThree" headertext="Column 3"/>
    </columns>
</asp:GridView>
于 2012-05-16T14:11:20.727 回答