3

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;
    }
}
DanM7
  • 2,203
  • 3
  • 28
  • 46
Joby
  • 379
  • 1
  • 3
  • 10

1 Answers1

0

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..

Mohit
  • 250
  • 1
  • 5
  • 16
  • Yes...You are correct...I have done the above code...but not working – Joby Nov 15 '10 at 09:01
  • 2
    When you use NeedDataSource, you don't call DataBind() or it will raise an exception – Arief Nov 15 '10 at 09:07
  • @Arief Iman Santoso....yes...it is correct...i can see the count in table[0]..but it not showing to datagrid...when i refresh the it will work.... – Joby Nov 15 '10 at 09:19
  • Yes Arief you are right.. The radgrid does not need to be bind here. – Mohit Nov 15 '10 at 10:12