I can page fine when the page loads. After I do a search let say my
stored procedure returns 200 results the first 10 show but when I click
on next page the it seems as if my search as been reset. It doesn't
let me see the 190 that are left to page through. Here is my code, if
that helps:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace GlossaryCreation.Forms
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected GlossaryCreation.Forms.DataSet3 dataSet31;
protected System.Data.DataView dataView1;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.DropDownList dpdlSearch;
protected System.Web.UI.WebControls.TextBox txtSearch;
protected System.Web.UI.WebControls.Label lblSearch;
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
DataView Source;
Source = (DataView)Cache["MyDataView"];
if(!Page.IsPostBack)
{
Page.RegisterHiddenField("__EVENTTARGET", "btnSearch");
SqlConnection conn = new SqlConnection("workstation id='';packet
size=4096;user id=id;data source=server;persi" +
"st security info=True;initial catalog=database;password=pass");
conn.Open();
// Create sqlCommand to select username and password from users
table
SqlCommand cmd = new SqlCommand("iDBGetHAMSSearchList",conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows)
{
this.dpdlSearch.DataSource = dr;
this.dpdlSearch.DataTextField = "column_name";
this.dpdlSearch.DataValueField = "column_name";
this.dpdlSearch.DataBind();
}
// close dr connection
dr.Close();
this.bindSearchResults();
//this.sqlDataAdapter1.Fill(this.dataSet31);
//dataView1.Sort = "Serial #";
//this.DataGrid1.DataBind();
//Cache["MyDataView"] = dataView1;
}
}
private void bindSearchResults()
{
this.dataSet31.Clear();
this.DataGrid1.DataSource = this.dataSet31;
this.sqlDataAdapter1.Fill(this.dataSet31);
this.DataGrid1.DataBind();
}
private void dataView1_ListChanged(object sender,
System.ComponentModel.ListChangedEventArgs e)
{
}
private void DataGrid1_SortCommand(object source,
DataGridSortCommandEventArgs e)
{
dataView1.Sort = e.SortExpression;
DataGrid1.DataBind();
}
public void DataGrid1_PageChanger(object sender,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.bindSearchResults();
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
this.DataGrid1.CurrentPageIndex = 0;
DataView Source;
Source = (DataView)Cache["MyDataView"];
if(Page.IsPostBack)
{
// Create and open connection to database containing the usernames
and password
SqlConnection conn1 = new SqlConnection("workstation id='';packet
size=4096;user id=id;data source=server;persi" +
"st security info=True;initial catalog=database;password=pass");
conn1.Open();
// Create sqlCommand to select username and password from users
table
SqlCommand cmd = conn1.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "iDBHAMSSearchAsset";
cmd.Parameters.Add("@ciSearch",SqlDbType.VarChar,50);
cmd.Parameters["@ciSearch"].Value = txtSearch.Text;
cmd.Parameters.Add("@ciDropList",SqlDbType.VarChar,15,"column_name");
cmd.Parameters["@ciDropList"].Value =
this.dpdlSearch.SelectedValue.ToString();
if (conn1.State == ConnectionState.Closed)
conn1.Open();
this.sqlDataAdapter1.SelectCommand = cmd;
sqlDataAdapter1.Fill(this.dataSet31);
this.DataGrid1.DataSource = this.dataSet31;
DataGrid1.DataBind();
//close sql conneciton
conn1.Close();
}
this.bindSearchResults();
}