0
我是新來的asp.net,需要一些幫助。我有一個GridView,每頁有20條記錄,我在GridView外面有一個搜索按鈕。我需要做的是,當我單擊搜索按鈕時,結果必須綁定到gridview(現在正在發生),但是當記錄超過pagesize並且我需要轉到網格的下一頁時,綁定會丟失,並且綁定的記錄是加載事件中形成頁面的記錄。下面是我的代碼示例。在按鈕上綁定GridView單擊分頁事件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
public void BindData()
{
{
List<EventFile> eventFile = new List<EventFile>();
eventFile = CoMailAssociationDAL.GetUploadFileUnAssigned(0, "", "", "U");
if (gvwAssociation.DataSource == null)
{
gvwAssociation.DataSource = eventFile;
gvwAssociation.DataBind();
}
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
int uFlag = 0;
string uploadFlag = this.ddlUploadDate.SelectedValue;
string fileName = this.txtSearchText.Text;
string uploadDt = this.txtDate.Text;
string status = this.ddlStatus.SelectedValue.ToString();
bt = true;
if (status == "Un-Assigned")
{
status = "U";
}
else if (status == "Assigned")
{
status = "A";
}
else
{
status = "B";
}
if ((uploadFlag == "On") && (uploadDt == ""))
{
uFlag = 0;
}
else if (uploadFlag == "On")
{
uFlag = 1;
}
else if (uploadFlag == "OnorBefore")
{
uFlag = 2;
}
else
{
uFlag = 3;
}
fileSearch = CoMailAssociationDAL.SearchFile(uFlag, fileName, uploadDt, status);
gvwAssociation.DataSource = fileSearch;
gvwAssociation.DataBind();
}
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//SaveSelectedValues();
gvwAssociation.PageIndex = e.NewPageIndex;
//BindData();
//PopulateSelectedValues();
}
感謝您的回答,我已經有了pageindex更改事件的代碼。你能向我展示一些你上面提到的東西的例子嗎?道歉,我真的是asp.net的新手。非常感謝幫助 – Moccassin
我剛更新了我的答案。看一看 – Sam
嗨,山姆,再次感謝您耐心回答我的問題。代碼有點不像預期的那樣工作。顯示所有記錄的條件始終滿足,並且不會進入else語句(用於篩選記錄) – Moccassin