簡體   English   中英

ASP.NET Gridview沒有顯示

[英]ASP.NET Gridview not showing

好吧所以我確定問題是在代碼背后,有些事情是不對的..

DAL是一個從數據庫中獲取數據的類,它確實有效。

代碼背后:

using DALLib;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FinalProject
{
    public partial class בתים : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MaxRooms.Attributes.Add("onChange", "return OnSelectedIndexChange()");
                MinRooms.Attributes.Add("onChange", "return OnSelectedIndexChange()");

                Cities.DataSource = (DataTable)Application["CitiesTable"];
                Cities.DataTextField = "Name";
                Cities.DataBind();
            }

            DAL findHouses = new DAL(
                "SELECT * FROM Houses WHERE City='" + Cities.Text + "' AND Rooms BETWEEN '" + MinRooms.Text + "' AND '" + MaxRooms.Text + "'",
                ConfigurationManager.AppSettings["ConnectionString"],
                "Houses"
                );

            Application.Lock();
            Application["SearchResultsTable"] = findHouses.GetTable();
            Application.UnLock();

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            SearchResults.PageIndex = e.NewPageIndex;
            BindHousesToGrid();
        } 

        private void BindHousesToGrid()
        {
            SearchResults.DataSource = (DataTable)Application["SearchResultsTable"];
            SearchResults.DataBind();
        }

    }
}

表格:

<div>
    <asp:GridView ID="SearchResults" runat="server" CellPadding="4" GridLines="None" AutoGenerateColumns="False" ForeColor="#333333" AllowPaging="True">
        <AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
        <Columns>
            <asp:BoundField DataField="Id" HeaderText="מספר נכס" />
            <asp:BoundField DataField="City" HeaderText="עיר" />
            <asp:BoundField DataField="Street" HeaderText="רחוב" />
            <asp:BoundField DataField="Rooms" HeaderText="חדרים" />
            <asp:BoundField DataField="size" HeaderText="גודל" />
            <asp:BoundField DataField="price" HeaderText="מחיר" />
        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White"></FooterStyle>

        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White"></HeaderStyle>

        <PagerStyle HorizontalAlign="Center" BackColor="#FFCC66" ForeColor="#333333"></PagerStyle>

        <RowStyle BackColor="#FFFBD6" ForeColor="#333333"></RowStyle>

        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy"></SelectedRowStyle>

        <SortedAscendingCellStyle BackColor="#FDF5AC"></SortedAscendingCellStyle>

        <SortedAscendingHeaderStyle BackColor="#4D0000"></SortedAscendingHeaderStyle>

        <SortedDescendingCellStyle BackColor="#FCF6C0"></SortedDescendingCellStyle>

        <SortedDescendingHeaderStyle BackColor="#820000"></SortedDescendingHeaderStyle>
    </asp:GridView>
</div>

我的表單上的按鈕還沒有做任何事情,但首先我希望gridview顯示初始值,意味着整個數據庫表..我做錯了什么?

網格未綁定到任何數據源。 添加到Page_Load:

BindHousesToGrid();

我還使用此代碼里面 if(!IsPostBack) { }塊,這樣你就不會檢索每一個回發相同的數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM