protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetData();
}
}
public void GetData()
{
string SQL=string.Empty;
SqlDataAdapter commandToBeLog=null;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
SQL = " SELECT * FROM tbl_Video";
if (txtSearchVideo.Text.Trim() != string.Empty)
{
SQL += " WHERE VideoName LIKE @VideoName ";
ListView1.DataSource = null;
}
SQL += " ORDER BY VideoID DESC";
DataSet ds = new DataSet();
SqlDataAdapter myCommand = new SqlDataAdapter(
SQL, con);
if (txtSearchVideo.Text.Trim() != string.Empty)
{
myCommand.SelectCommand.Parameters.Add("@VideoName", SqlDbType.NVarChar, 300).Value = "%" + txtSearchVideo.Text + "%";
}
myCommand.Fill(ds);
ListView1.DataSource = ds;
ListView1.DataBind();
}
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
this.GetData();
}
protected void btnSerch_Click(object sender, EventArgs e)
{
if (txtSearchVideo.Text.Trim() != string.Empty)
{
GetData();
GetData();
}
else
{
GetData();
}
}
Hi, how do i make the list view paging is no depedent to the textbox search. I got a problem with listview search pager, whenever I click search button with textbox value equal to A, the btnSerch_Click event fire. It show out 3 pages data with results and then I navigate to page 3. But when I type in the textbox with value B(it suppose show one page data), and I didnt click search button, but i go to click page 2. The weird thing happen, it show not relevant data or broken data.
How do i solve this problem, i don't want the page navigate bar depedent to the textbox. What I mean is I click page 2, the GetData() fucntion not fire, but just the page trigger only.
You need to to remove this line
from the
GetDatamethod. Because if younullthe ListView, the properties you set inListView1_PagePropertiesChangingwill be lost.And you can reduce the Button click method to just one line.