Question

I am using Radgrid with pager. When clicking on the next page number on a pager the data is not displaying(not binding the data). Can anyone help me to fix this. here is my code.

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        if (!IsPostBack)
        {
            Session["SearchRes"] = null;
            if (Session["TaskName"] != null)
                lblTskName.Text = Session["TaskName"].ToString();
            Session["FilColms"] = null;
            Session["SortExp"] = null;
            Session["FilExp"] = null;
            Session["ViewAll"] = null;
            BindGrid();
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

private void BindGrid()
{
    try
    {
        DataSet dsResult = new DataSet();

        clsSearch_BL clsObj = new clsSearch_BL();
        clsObj.TaskID = (string)Session["TaskID"];
        clsObj.CustName = (string)Session["CustName"];
        clsObj.MarketName = (string)Session["MarketName"];
        clsObj.HeadendName = (string)Session["HeadendName"];
        clsObj.SiteName = (string)Session["SiteName"];
        clsObj.TaskStatus = (string)Session["TaskStatus"];
        clsObj.OrdType = (string)Session["OrdType"];
        clsObj.OrdStatus = (string)Session["OrdStatus"];
        clsObj.ProName = (string)Session["ProName"];
        clsObj.LOC = (string)Session["LOC"];
        clsObj.QuoteID = (string)Session["QuoteID"];
        clsObj.CMNumber = (string)Session["CMNumber"];

        if (Session["SearchRes"] == null)
        {
            dsResult = clsObj.getSearchResults_BL(clsObj);
            Session["SearchRes"] = dsResult;
        }
        else
            dsResult = (DataSet)Session["SearchRes"];

        DataView dataView = dsResult.Tables[0].DefaultView;
        rg200.DataSource = dsResult;
        rg200.DataBind();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

protected void rg200_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{

    if (Session["TaskID"] != null)
    {
        string strTaskID = (string)Session["TaskID"];
        if (strTaskID != string.Empty)
        {
            clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();

            GridEditableItem editedItem = e.Item as GridEditableItem;
            //Get the primary key value using the DataKeyValue.      
            string OrdID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["orderId"].ToString();
            //Access the textbox from the edit form template and store the values in string variables.

            string ClarifyAccountNbr = ((GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("Clarify Account Nbr")).TextBoxControl.Text;

            string SiteID = ((GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("Site ID")).TextBoxControl.Text;

            string QuoteID = ((GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("Quote ID")).TextBoxControl.Text;

            CheckBox chkEDP = ((GridCheckBoxColumnEditor)editedItem.EditManager.GetColumnEditor("EDP Created?")).CheckBoxControl;

            //string ClarifyAccountNbr = (editedItem["Clarify Account Nbr"].Controls[0] as TextBox).Text;
            //string SiteID = (editedItem["Site ID"].Controls[0] as TextBox).Text;
            //string QuoteID = (editedItem["Quote ID"].Controls[0] as TextBox).Text;
            //CheckBox chkEDP = (editedItem["EDP Created?"].Controls[0] as CheckBox);
            try
            {
                objBL.setTask200_Bl(OrdID, ClarifyAccountNbr, SiteID, QuoteID, chkEDP.Checked);
                Session["SearchRes"] = null;

                BindGrid();

            }
            catch (Exception ex)
            {
                rg200.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));
                e.Canceled = true;
            }
        }
    }
}
protected void rg200_PageIndexChanged(object source, GridPageChangedEventArgs e)
{
    try
    {
        rg200.CurrentPageIndex = e.NewPageIndex;
        BindGrid();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
Was it helpful?

Solution

Your code shows that you use binding with DataBind() calls. In this way you should manually change the page index hooking PageIndexChanged, assign data source to the grid and bind it. Alternatively, use NeedDataSource binding to spare some manual coding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top