开发者

CollectionPager Problem With UpdatePanel

开发者 https://www.devze.com 2023-03-29 22:27 出处:网络
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 fi

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 A开发者_StackOverflow中文版SC");
}}

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);}


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


try this EnableViewState="false"


You have to bind the CollectionPager again on your search.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号