【发布时间】:2017-01-20 15:32:27
【问题描述】:
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();
}
}
嗨,我如何使列表视图分页不依赖于文本框搜索。我遇到了 listview 搜索寻呼机的问题,每当我单击文本框值等于 A 的搜索按钮时,btnSerch_Click 事件就会触发。它显示了 3 页数据和结果,然后我导航到第 3 页。但是当我在文本框中键入值 B(它假设显示一页数据)时,我没有单击搜索按钮,但我去单击第 2 页。奇怪的事情发生了,它显示不相关的数据或损坏的数据。
如何解决这个问题,我不希望页面导航栏依赖于文本框。我的意思是我单击第 2 页,GetData() 函数不会触发,而只是页面触发。
【问题讨论】:
标签: c# asp.net listview datapager