This is a migrated thread and some comments may be shown as answers.

RadGrid Paging Issue

3 Answers 284 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 14 May 2009, 08:46 PM

Hi all:

I have a web application where I need the RadGrid to populate with data based on a selection from a DropDown list box. The grid also needs to have paging so I followed the samples on the Telerik site and used OnNeedDataSource to enable the paging. The issue is that when I make a selection from the drop down list, the OnNeedDataSource is called twice, and it doesn't even read the correct value from the drop-down, it always returns 0 as the Selected Index.

I think it has something to do with the OnNeedDataSource being called as part of page load, and so the postback from the drop-down fires the method, but I don’t understand why it runs twice.

Has anyone had any experience with this and know how I can fix this? OR can anyone make a suggestion for a better idea? The selections in the drop-down are dynamic and loaded at run-time, and then what is selected from the drop-down determines what data loads in the RadGrid.

Thanks.

John.

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 18 May 2009, 08:38 AM
Hello John,

This behavior is not expected but without a concrete example of your implementation it is difficult to say what exactly the issue might be.

Please, take a look at the attached sample and at the following help article: Event Sequence.

I hope this information will help you on the right track with your implementation.

Sincerely yours,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John
Top achievements
Rank 1
answered on 20 May 2009, 12:20 AM
Thanks for the sample. Would the sample work the same way if I were first building a data table and then binidng to the RadGrid? Due to the grid columns being added according to what the user selects, I cannot use a Sql.Select as you did...

Also, would it be possible for you to add column sorting and paging to the example? I have hit some errors getting that working...I have pasted the DataTable method below, but please note it retrieves data from Dynamics CRM, and then uses that data to add the RadGrid columns. The examples on the Telerik site use OnNeedDataSource for paging and sorting, but I cannot use that as it fires right after the Page_Load, and I have to fetch the data and build the grid only after a selection has been made from the Drop-Down.

So in the DropDown_OnSelectedIndexChanged, I do this:

 DataTable dtLL = getLongListTable(ref bRfpSelected, ref strSelectedRfp, "");
    if (dtLL.Rows.Count > 0)
    {
      gridLongList.DataSource = dtLL;
      gridLongList.DataBind();
      Session["LongListSortDir"] = "ASC";
    }

and then I tried using OnPageIndexChanged with this:

      gridLongList.DataSource = getLongListTable(ref bRfpSelected, ref strSelectedRfp, "");
      gridLongList.Rebind();

and then I tried using SortCommand thus:

//===============================================================================================
//===============================================================================================
  protected void gridLongList_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
  {
    if (Session["LongListSortDir"] == "ASC")
    {
      Session["LongListSortDir"] = "DESC";
      gridLongList.DataSource = getLongListTable(ref bRfpSelected, ref strSelectedRfp, "DESC");
      gridLongList.DataBind();
    }
    else
    {
      Session["LongListSortDir"] = "ASC";
      gridLongList.DataSource = getLongListTable(ref bRfpSelected, ref strSelectedRfp, "");
      gridLongList.DataBind();
    }
  }

Thanks for any and all advice.

If you email me at jstraumann@hotmail.com I would be happy to send the whole file.

John.

  public DataTable getLongListTable(ref bool bRFP, ref string strRFP, string strSortDir)
  {
    txtDebug.Text += "getLongListTable()\n";

    DataTable dtLongList = new DataTable();
    DataColumn column;
    bool bLLName = false;
    bool bLLAddress = false;
    bool bLLCity = false;
    bool bLLZip = false;
    bool bLLDist = false;
    bool bLLCode = false;

    //if (bRFP)
    //{
    if (drpActiveRfps.SelectedIndex > 0)
    {
      txtDebug.Text += strRFP + "\n";
      try
      {
        #region webservices
        strUniqueName = WebConfigurationManager.AppSettings["UniqueName"].ToString();
        strOrgName = WebConfigurationManager.AppSettings["OrgName"].ToString();
        strServerName = WebConfigurationManager.AppSettings["ServerName"].ToString();

        //Initialize CRM web services============
        CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.AuthenticationType = 0;
        //token.OrganizationName = "AccommodationsPlusInternationa";
        token.OrganizationName = strOrgName;

        CrmService service = new CrmService();
        //service.Url = "http://moss:5555/mscrmservices/2007/crmservice.asmx?WSDL&uniquename=accommodationsplusinternationa";
        service.Url = "http://" + strServerName + "/mscrmservices/2007/crmservice.asmx?WSDL&uniquename=" + strUniqueName;
        service.CrmAuthenticationTokenValue = token;
        service.Credentials = System.Net.CredentialCache.DefaultCredentials;
        //End Initialize CRM web services========
        #endregion

        // rfpGuid is the GUID of the RFP being retrieved.
        Guid rfpGuid = new Guid(strRFP);

        // Retrieve the RFP.
        new_rfpprogram theRfp = (new_rfpprogram)service.Retrieve(EntityName.new_rfpprogram.ToString(), rfpGuid, new AllColumns());

        #region longlist
        bool bLLColumns = false;

        #region retrieve
        //Retrieve the RFPSent records for the RFP (i.e. the Long List);
        // Create the ConditionExpression.
        ConditionExpression condition = new ConditionExpression();

        //Set the condition for the retrieval to be when the RFP Guid on the
        //RFP Sent record matches the RFP ID.
        condition.AttributeName = "new_rfpprogramid";
        condition.Operator = ConditionOperator.Equal;
        condition.Values = new string[] { rfpGuid.ToString() };

        // Create the FilterExpression.
        FilterExpression filter = new FilterExpression();

        // Set the properties of the filter.
        filter.FilterOperator = LogicalOperator.And;
        filter.Conditions = new ConditionExpression[] { condition };

        // Create the QueryExpression object.
        QueryExpression query = new QueryExpression();

        // Set the properties of the QueryExpression object.
        //query.EntityName = EntityName.new_rfpsent.ToString();
        query.EntityName = EntityName.new_longlist.ToString();
        query.ColumnSet = new AllColumns();
        query.Criteria = filter;

        // Create the request object.
        RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();

        // Set the properties of the request object.
        retrieve.Query = query;

        // Retrieve the "Long List" of hotels that the RFP was sent to
        //CRM Entity: new_rfpsent
        RetrieveMultipleResponse retrievedLongList = (RetrieveMultipleResponse)service.Execute(retrieve);

        string strAirportCode = "";
        string strCname = "Dist to ";
        for (int i = 0; i < retrievedLongList.BusinessEntityCollection.BusinessEntities.Length; i++)
        {
          //new_rfpsent rfpSent = (new_rfpsent)retrievedLongList.BusinessEntityCollection.BusinessEntities[i];
          new_longlist longList = (new_longlist)retrievedLongList.BusinessEntityCollection.BusinessEntities[i];
          //strAirportCode = longList.new_ rfpSent.new_airportcode;
          //Add to the Long List ArrayList
          //alistLongList.Add(rfpSent);
          alistLongList.Add(longList);
        }
        #endregion

        #region columns
        //Build the data table for displaying the Long List
        //Possible Columns are HotelName, Street Address, City, Zip, Distance, and Code
        //The end users will make the column selection on the RFPProgram record
        //in CRM, and the columns are added according to the selections made.
        //Long List Columns
        if (theRfp.new_longlistname != null && theRfp.new_longlistname.Value == true)
        {
          bLLColumns = true;
          bLLName = true;
          column = new DataColumn();
          //column.DataType = System.Type.GetType("String");
          column.ColumnName = "Hotel Name";
          column.ReadOnly = true;
          //column.Unique = true;
          dtLongList.Columns.Add(column);
        }
        if (theRfp.new_longlistaddress != null && theRfp.new_longlistaddress.Value == true)
        {
          bLLColumns = true;
          bLLAddress = true;
          column = new DataColumn();
          //column.DataType = System.Type.GetType("String");
          column.ColumnName = "Street Address";
          column.ReadOnly = true;
          //column.Unique = true;
          dtLongList.Columns.Add(column);
        }
        if (theRfp.new_longlistcity != null && theRfp.new_longlistcity.Value == true)
        {
          bLLColumns = true;
          bLLCity = true;
          column = new DataColumn();
          //column.DataType = System.Type.GetType("String");
          column.ColumnName = "City";
          column.ReadOnly = true;
          //column.Unique = true;
          dtLongList.Columns.Add(column);
        }
        if (theRfp.new_longlistzip != null && theRfp.new_longlistzip.Value == true)
        {
          bLLColumns = true;
          bLLZip = true;
          column = new DataColumn();
          //column.DataType = System.Type.GetType("String");
          column.ColumnName = "Zip";
          column.ReadOnly = true;
          //column.Unique = true;
          dtLongList.Columns.Add(column);
        }
        if (theRfp.new_longlistdist != null && theRfp.new_longlistdist.Value == true)
        {
          bLLColumns = true;
          bLLDist = true;
          column = new DataColumn();
          //column.DataType = System.Type.GetType("String");
          strCname += theRfp.new_airport;
          column.ColumnName = strCname;
          column.ReadOnly = true;
          //column.Unique = true;
          dtLongList.Columns.Add(column);
        }
        if (theRfp.new_longlistcode != null && theRfp.new_longlistcode.Value == true)
        {
          bLLColumns = true;
          bLLCode = true;
          column = new DataColumn();
          //column.DataType = System.Type.GetType("String");
          column.ColumnName = "Code";
          column.ReadOnly = true;
          //column.Unique = true;
          dtLongList.Columns.Add(column);
        }
        #endregion

        //Sort the list
        if (strSortDir == "DESC")
        {
          alistLongList.Sort(new RfpResponseHotelNameComparerDesc());
          Session["LongListSortDir"] = "DESC";
        }
        else
        {
          alistLongList.Sort(new RfpResponseHotelNameComparer());
          Session["LongListSortDir"] = "ASC";
        }

        #region datatable
        if (bLLColumns)
        {
          for (int i = 0; i < alistLongList.Count; i++)
          {
            new_longlist longListHotel = (new_longlist)alistLongList[i];
            //new_rfpsent rfpSent = (new_rfpsent)alistLongList[i];
            // Retrieve the Hotel.
            new_hotel theHotel = (new_hotel)service.Retrieve(EntityName.new_hotel.ToString(), longListHotel.new_hotelid.Value, new AllColumns());

            DataRow theRow = dtLongList.NewRow();
            if (bLLName)
              theRow["Hotel Name"] = theHotel.new_hotname;
            if (bLLAddress)
              theRow["Street Address"] = theHotel.new_hotstreet1;
            if (bLLCity)
            {
              for (int j = 0; j < alistCities.Count; j++)
              {
                new_city tC = (new_city)alistCities[j];
                if (tC.new_cityid.Value.ToString() == theHotel.new_nearmajorcityid.Value.ToString())
                  theRow["City"] = tC.new_name;
              }
            }
            if (bLLZip)
              theRow["Zip"] = theHotel.new_hotzipcode;
            if (bLLDist)
              theRow[strCname] = theHotel.new_airportdistance;
            if (bLLCode)
              theRow["Code"] = "D";
            dtLongList.Rows.Add(theRow);
            //txtDebug.Text += rfpSent.new_name + " " + rfpSent"\n";
          }
        #endregion
          //gridLongList.DataSource = dtLongList;
          //gridLongList.DataBind();
        }
        else
          MessageBox.Show("No Long List Display Columns Selected on the RFP Program Entity");
        #endregion
      }
      catch (System.Web.Services.Protocols.SoapException soapEx)
      {
        txtDebug.Text += "SOAP exception: " + soapEx.Detail.InnerText + "  " + soapEx.ToString();
        //sw1.WriteLine("SOAP exception: " + soapEx.Detail.InnerText + "  " + soapEx.ToString());
      }
      catch (Exception ex)
      {
        txtDebug.Text += "General exception: " + ex.StackTrace.ToString() + "\n" + ex.ToString();
        //sw1.WriteLine("General exception: " + ex.StackTrace.ToString() + "\n" + ex.ToString());
      }
    }
    //}
    return dtLongList;
  }

0
Tsvetoslav
Telerik team
answered on 20 May 2009, 02:06 PM
Hi John,

Could you, please, send a test project at: Tsvetoslav.Kovachev@telerik.com

Thank you.

Kind regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
John
Top achievements
Rank 1
Share this question
or