中继器绑定连接后闭幕 [英] Connection closing after repeater databinding

查看:137
本文介绍了中继器绑定连接后闭幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近改变了在连接上我的web应用程序的工作方式,现在我面对的东西,我不明白。

我哈瓦调用一个称为ItemGet在Page_Load功能的页并完美时,有在第一中继器(Repeater1)无数据它的工作。当我点击了刷新不同的数据页面的按钮(我知道有数据中继),连接同中继器(中继器1)右后自动关闭。的问题是,有(RepeaterTopTen)需要相同的连接后其他中继器的权利。我手动关闭调用该函数之后的连接,但至少我需要连接的所有功能中保持开放。

做任何你知道为什么它关闭自己和我能做些什么,以prevent它关闭在这个时候?

下面是code:

 私人无效ItemsGet(字符串csCategory,串csTimeFrame)
{
    数据集的数据;    如果(csCategory == NULL)
    {
        数据= m_database.GetPost(Tools.GetPostLang(),会话[时间表]的ToString());
        Page.Title = m_database.GetTranslation(509);
    }
    其他
    {
        数据= m_database.GetPost(Convert.ToInt32(csCategory),Tools.GetPostLang(),会话[时间表]的ToString());
        Page.Title = m_database.GetTranslation(508)+ m_database.GetCategoryName(Convert.ToInt32(csCategory));
    }    //填充的项目DataSet中的中继控制
    PagedDataSource objPds =新PagedDataSource();
    objPds.DataSource =(数据视图)(data.Tables [0] .DefaultView);    //表示数据应该被寻呼
    objPds.AllowPaging = TRUE;    //设置你希望每页显示的项目数
    objPds.PageSize = 5;    //设置PagedDataSource的当前页面
    如果(当前页!= ​​0)
        objPds.CurrentPageIndex =当前页;
    其他
        objPds.CurrentPageIndex = 0;    lblCurrentPage.Text = m_database.GetTranslation(423)+(当前页+1)的ToString()+ m_database.GetTranslation(422)+ objPds.PageCount.ToString();    //禁用preV或者如果需要的话下一个按钮
    BTN prev.Enabled = objPds.IsFirstPage!;
    btnNext.Enabled = objPds.IsLastPage!;    Repeater1.DataSource = objPds;
    Repeater1.DataBind();    数据集dataTopTen = m_database.GetTopTenUser();
    RepeaterTopTen.DataSource = dataTopTen;
    RepeaterTopTen.DataBind();}


解决方案

如果你宣布你的数据库对象,然后调用open方法在的Page_Load 方法的数据库连接上,那么数据库连接将保持你的整个页面生命周期开放。有了这个功能你声明的数据库连接,数据库对象超出范围,当你的函数结束被关闭。

I recently changed the way the connection worked on my web app and now I'm facing something that I don't understand.

I hava a page that call a function called "ItemGet" in the Page_Load and it work perfectly when there is no data in the first repeater (Repeater1). When I click on a button that reload the page with different data (I know there is data in the repeater), the connection is closed automatically right after that same repeater (Repeater 1). The problem, is that there is another repeater right after (RepeaterTopTen) that need the same connection. I closed manually the connection right after the call to that function but at least I need the connection to stay open during all the function.

Do any of you know the reason why it closed itself and what I can do to prevent it to close at this time?

Here is the code :

private void ItemsGet(string csCategory, string csTimeFrame)
{
    DataSet data;

    if (csCategory == null)
    {
        data = m_database.GetPost(Tools.GetPostLang(), Session["TimeFrame"].ToString());
        Page.Title = m_database.GetTranslation(509);
    }
    else
    {
        data = m_database.GetPost(Convert.ToInt32(csCategory), Tools.GetPostLang(), Session["TimeFrame"].ToString());
        Page.Title = m_database.GetTranslation(508) + m_database.GetCategoryName(Convert.ToInt32(csCategory));
    }         

    // Populate the repeater control with the Items DataSet
    PagedDataSource objPds = new PagedDataSource();
    objPds.DataSource = (DataView)(data.Tables[0].DefaultView);

    // Indicate that the data should be paged
    objPds.AllowPaging = true;

    // Set the number of items you wish to display per page
    objPds.PageSize = 5;

    // Set the PagedDataSource's current page
    if (CurrentPage != 0)
        objPds.CurrentPageIndex = CurrentPage;
    else
        objPds.CurrentPageIndex = 0;

    lblCurrentPage.Text = m_database.GetTranslation(423) + (CurrentPage + 1).ToString() + m_database.GetTranslation(422) + objPds.PageCount.ToString();

    // Disable Prev or Next buttons if necessary
    btnPrev.Enabled = !objPds.IsFirstPage;
    btnNext.Enabled = !objPds.IsLastPage;

    Repeater1.DataSource = objPds;
    Repeater1.DataBind();

    DataSet dataTopTen = m_database.GetTopTenUser();
    RepeaterTopTen.DataSource = dataTopTen;
    RepeaterTopTen.DataBind();

}

解决方案

If you declare your database object and call the open method on the database connection in your Page_Load method, then the database connection will remain open during your entire page life cycle. With your database connection declared in this function, the database object goes out of scope and gets closed when your function ends.

这篇关于中继器绑定连接后闭幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆