CollectionPager Problem With UpdatePanel

时光怂恿深爱的人放手 提交于 2019-12-17 20:42:48

问题


I have a problem with the collectionpager and repeater. When I load the page, collectionpager is working fine.. But when I click the search button and bind new data, clicking the page 2 link, it is firing the page_load event handler and bring all the data back again... Notice: All controls are in an UpdatePanel.

 protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{
    kayit_getir("SELECT Tbl_Icerikler.ID,Tbl_Icerikler.url,Tbl_Icerikler.durum,Tbl_Icerikler.baslik,Tbl_Icerikler.gunc_tarihi,Tbl_Icerikler.kayit_tarihi,Tbl_Icerikler.sira,Tbl_Kategoriler.kategori_adi FROM Tbl_Icerikler,Tbl_Kategoriler where Tbl_Kategoriler.ID=Tbl_Icerikler.kategori_id ORDER BY Tbl_Icerikler.ID DESC,Tbl_Icerikler.sira ASC");
}}

public void kayit_getir(string SQL){
SqlConnection baglanti = new SqlConnection(f.baglan());
baglanti.Open();
SqlCommand komut = new SqlCommand(SQL, baglanti);
SqlDataAdapter da = new SqlDataAdapter(komut);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
    CollectionPager1.DataSource = dt.DefaultView;
    CollectionPager1.BindToControl = Liste;
    Liste.DataSource = CollectionPager1.DataSourcePaged;
}
else
{
   kayit_yok.Text = "<br /><span class='message information'>Kayıt bulunamadı.</span>";
}
da.Dispose();
baglanti.Close();
CollectionPager1.DataBind();
Liste.DataBind();}


protected void search_Click(object sender, EventArgs e){
string adi = f.temizle(baslik.Text);
string durum = Durum.SelectedValue;
string kayit_bas_t = kayit_bas_tarih.Text;
string kayit_bit_t = kayit_bit_tarih.Text;
string kategori = kategori_adi.SelectedValue;


string SQL = "SELECT Tbl_Icerikler.ID,Tbl_Icerikler.url,Tbl_Icerikler.durum,Tbl_Icerikler.baslik,Tbl_Icerikler.gunc_tarihi,Tbl_Icerikler.kayit_tarihi,Tbl_Icerikler.sira,Tbl_Kategoriler.kategori_adi FROM Tbl_Icerikler,Tbl_Kategoriler where Tbl_Kategoriler.ID=Tbl_Icerikler.kategori_id and";
if (adi != "")
{
    SQL = SQL + " Tbl_Icerikler.baslik LIKE '%" + adi + "%' and";
}

if (kategori != "")
{
    SQL = SQL + " Tbl_Icerikler.kategori_id=" + kategori + " and";
}

if (durum != "")
{
    SQL = SQL + " Tbl_Icerikler.durum='" + durum + "' and";
}

if (kayit_bas_t != "")
{
    SQL = SQL + " (Tbl_Icerikler.kayit_tarihi>'" + kayit_bas_t + "') and";
}

if (kayit_bit_t != "")
{
    SQL = SQL + " (Tbl_Icerikler.kayit_tarihi<'" + kayit_bit_t + "') and";
}

SQL = SQL.Remove(SQL.Length - 3, 3);
SQL = SQL + " ORDER BY sira ASC,ID DESC";

try
{
    kayit_getir(SQL);
}
catch { }
Recursive(0, 0);}

回答1:


the code is very bad and you should completely review all of it. the issue is every time the page load is executed it initializes again you query to the default one (the one with not filter) you should find a way to store somewhere the last query has been execute when you order/filtering your data. Anyway the are lot of example on the web showing what you are trying to achieve

the below is just one of them

http://www.codeproject.com/KB/webforms/ExtendedRepeater.aspx




回答2:


try this EnableViewState="false"




回答3:


You have to bind the CollectionPager again on your search.



来源:https://stackoverflow.com/questions/7173465/collectionpager-problem-with-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!