0
确定,所以我确定问题出在后面的代码,什么是不正确..ASP.NET的GridView不显示
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显示初始值,意味着整个数据库表.. 我做错了什么?
完成,仍然没有显示.. :( –
更新您的源代码,请 – nativehr
感谢您的回答,它定了! 现在我和我的sql查询不同的问题单击按钮时...将打开一个新的线程 –