删除 RadGrid 中的第 11 行使其变为空白

发布于 2024-10-02 15:16:31 字数 2004 浏览 4 评论 0原文

我有一台 Telerik RadGrid。我使用一种方法来填充网格。我已启用分页属性。我使用 ItemTemplate-->ImageButton 作为删除和编辑选项。我已将页面大小设置为 10。页面加载时间正常工作并填充网格。插入第 11 行后,分页开始,它将在下一页中显示一条记录。但是当我删除第 11 行时,网格变为空白。我已经使用数据集来绑定记录。

radgrid.DataBind();
dsDataset.Dispose();

但它的item.count却是0,这是什么原因呢?

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        if (!IsPostBack)
        {
            PopulatePackage();
        }
    }
    catch (Exception ex)
    {
        lblMessage.Text = objUtl.GetErrorMessage(ex, this);
        lblMessage.Visible = true;

protected void gvPackage_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    try
    {
        SqlHelper objSQL = new SqlHelper();
        DataSet dsPackage = new DataSet();
        dsPackage = objSQL.ExecuteDataset("AL_PackageType_List_Retrieve", objUtl.NumericEntry(Session["LocationId"].ToString()));
        gvPackage.DataSource = dsPackage.Tables[0];
        dsPackage.Dispose();
        //PopulatePackage();
    }
    catch (Exception ex)
    {
        lblMessage.Text = objUtl.GetErrorMessage(ex, this);
        lblMessage.Visible = true;
    }
}

private void PopulatePackage()
{
    try
    {
        lblMessage.Text = string.Empty;
        SqlHelper objSQL = new SqlHelper();
        DataSet dsPackage = new DataSet();
        dsPackage = objSQL.ExecuteDataset("AL_PackageType_List_Retrieve", objUtl.NumericEntry(Session["LocationId"].ToString()));
        gvPackage.DataSource = null;
        gvPackage.DataSource = dsPackage.Tables[0];
        gvPackage.DataBind();
        //dsPackage.Dispose();
        if (gvPackage.Items.Count <= 0)
        {
            lblMessage.Text = "No Package Details Found...";
            gvPackage.Visible = false;
        }
        else
        {
            gvPackage.Visible = true;
        }
    }
    catch (Exception ex)
    {
        lblMessage.Text = objUtl.GetErrorMessage(ex, this);
        lblMessage.Visible = true;
    }
}

I have one Telerik RadGrid. Using a method I am filling the grid. I have enabled the paging property. I have used ItemTemplate-->ImageButton for delete and edit options. I have set page size as 10. Page load time is working properly and populating the grid. After inserting the 11th row the pagination starts and it will show in the next page with one record. But when I am deleting the 11th row the grid becomes blank. I have used dataset to bind the records.

radgrid.DataBind();
dsDataset.Dispose();

But its item.count is 0. What is the reason?

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        if (!IsPostBack)
        {
            PopulatePackage();
        }
    }
    catch (Exception ex)
    {
        lblMessage.Text = objUtl.GetErrorMessage(ex, this);
        lblMessage.Visible = true;

protected void gvPackage_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    try
    {
        SqlHelper objSQL = new SqlHelper();
        DataSet dsPackage = new DataSet();
        dsPackage = objSQL.ExecuteDataset("AL_PackageType_List_Retrieve", objUtl.NumericEntry(Session["LocationId"].ToString()));
        gvPackage.DataSource = dsPackage.Tables[0];
        dsPackage.Dispose();
        //PopulatePackage();
    }
    catch (Exception ex)
    {
        lblMessage.Text = objUtl.GetErrorMessage(ex, this);
        lblMessage.Visible = true;
    }
}

private void PopulatePackage()
{
    try
    {
        lblMessage.Text = string.Empty;
        SqlHelper objSQL = new SqlHelper();
        DataSet dsPackage = new DataSet();
        dsPackage = objSQL.ExecuteDataset("AL_PackageType_List_Retrieve", objUtl.NumericEntry(Session["LocationId"].ToString()));
        gvPackage.DataSource = null;
        gvPackage.DataSource = dsPackage.Tables[0];
        gvPackage.DataBind();
        //dsPackage.Dispose();
        if (gvPackage.Items.Count <= 0)
        {
            lblMessage.Text = "No Package Details Found...";
            gvPackage.Visible = false;
        }
        else
        {
            gvPackage.Visible = true;
        }
    }
    catch (Exception ex)
    {
        lblMessage.Text = objUtl.GetErrorMessage(ex, this);
        lblMessage.Visible = true;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我还不会笑 2024-10-09 15:16:31

好吧,据我了解,您有一个 radgrid,其中允许分页并将页面大小设置为 10。插入第 11 条记录后,会显示一个包含第 11 条记录的新页面。当第 11 条记录被删除时,您将看到一个空白页面,而不是显示具有从 1 到 10 的记录的页面。我希望我就在这里。

反正。我猜问题是 Radgrid 没有您现在正在查看的页面的数据。

RadGrid 中有一个名为 NeedDataSource 的事件。每当 RadGrid 需要显示数据时,就会触发此事件。您可以在此事件中调用绑定逻辑,看看它是否适合您。

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindGrid();
    }
}

private void BindGrid()
{
    RadGrid1.DataSource = "BindingSource";
    RadGrid1.DataBind();
}

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    BindGrid();
}

看看这是否适合你..

Okay as far as I am understanding it, You have a radgrid in which you have allowed paging and set the page size to 10. Upon inserting the 11th record a new page is shown with that 11th record. And when that 11th record is deleted you are viewing a blank page, instead of showing the page having record from 1 to 10. I hope I am right here.

Anyway. I guess the problem is that the Radgrid is not having the data for the page you are viewing now.

There is an event in RadGrid named NeedDataSource. This Event is fired up whenever the RadGrid needs to display the data. You can call the Binding logic in this event and see if it works for you.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindGrid();
    }
}

private void BindGrid()
{
    RadGrid1.DataSource = "BindingSource";
    RadGrid1.DataBind();
}

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    BindGrid();
}

See if this works for you..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文