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

RadGrid Inside RadMultiPage Disappears when paging, sorting, etc...

3 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 11 May 2011, 04:46 PM

I've seen a couple other posts about this, but none of them had an answer that actually worked. My problem is that I have a RadGrid inside of a RadMultiPage, and I'm using RadAjaxManager. Whenever I click to go to the next page, or change the page size, or anything of that nature, the RadGrid disappears. When looking at the source code the markup for the RadGrid does not appear, just a couple of div tags in its place. This is the code on my .aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateAccount.aspx.cs" Inherits="DADCA.Account.CreateAccount" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head id="Head1" runat="server">
    <title>Dayton Defense - Login</title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        /*the following CSS rules take care of expanding the html, body and form elements
        in case the page content is shorter than the browser window viewport.*/
  
        html,
        body,
        form
        {
            min-height:100%; /*all except IE6*/
            margin:0;
            padding:0;
        }
  
        * html html,
        * html body,
        * html form
        {
            height:100%; /*IE6 only*/
        }
  
        .MyModalPanel
        {
            position:absolute;
        }
    </style>
</head>
<body style="background: #fff; ">
    <form id="page_form" runat="server">
    <div style="width:500px; margin: 20px auto 0px auto !important;">
        <telerik:RadScriptManager ID="LoginRadScriptManager" runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadSubmitButton">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="createAccountMultiPage" LoadingPanelID="win7LoadingPanel" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="companySearchResultsGrid">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="createAccountPanel" LoadingPanelID="win7LoadingPanel" />
                        <telerik:AjaxUpdatedControl ControlID="companySearchResultsGrid" />
                        <telerik:AjaxUpdatedControl ControlID="createAccountMultiPage" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="win7LoadingPanel" runat="server" CssClass="MyModalPanel" Skin="Windows7" IsSticky="true" Width="100%" Height="100%" />
        <telerik:RadMultiPage ID="createAccountMultiPage" runat="server" Width="100%">
            <telerik:RadPageView ID="companySearchView" runat="server" Selected="true">
                <table width="100%" align="center">
                    <tr>
                        <td> </td>
                    </tr>
                    <tr>
                        <td width="40%" align="left">
                            <img src="../Images/DaytonDefenseLogo.jpg" alt="Dayton Defense Logo" width="100%"/>
                        </td>
                        <td width="5%"></td>
                        <td align="left" valign="top" width="55%">
                            <h1>Register</h1>
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                </table>
                <table width="100%" align="center">
                    <tr>
                        <td colspan="3" align="center">
                            Please enter your company's name in the textbox below and click "Submit".<br /><br />
                            This will search our database to see if a record of your company already exists. 
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                            <span class="failureNotification">
                                <span style="color: Red">
                                    <asp:Label ID="errorLabel" runat="server" Visible="false" />
                                </span>
                            </span>
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td width="48%" align="right">
                            <span id="asterikSpan" style="color:Red;" runat="server" visible="false">*</span>Company Name: 
                        </td>
                        <td width="2%"> </td>
                        <td align="left">
                            <telerik:RadTextBox ID="companyName" runat="server" Skin="Windows7" />
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3" align="center">
                            <telerik:RadButton ID="RadSubmitButton" runat="server" OnClick="RadSubmitButton_OnClick" Text="Submit"  Skin="Windows7" Width="150px" ValidationGroup="LoginUserValidationGroup" />
                        </td>
                    </tr>
                </table>
            </telerik:RadPageView>
            <telerik:RadPageView ID="companySearchResultsView" runat="server">
                <table width="100%" align="center">
                    <tr>
                        <td> </td>
                    </tr>
                    <tr>
                        <td width="40%" align="left">
                            <img src="../Images/DaytonDefenseLogo.jpg" alt="Dayton Defense Logo" width="100%"/>
                        </td>
                        <td width="5%"></td>
                        <td align="left" valign="top">
                            <h1>Register</h1>
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                </table>
                <table width="95%" align="center">
                    <tr>
                        <td colspan="3" align="right" width="100%">
                            <telerik:RadButton ID="backToSearchButton" runat="server" Text="Back To Company Search" Skin="Windows7" OnClick="backToSearchButton_OnClick" />
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3" align="center" width="100%">
                            Below are the results of your search.
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                            If you see your company listed, click on the check mark to view details about your company and how to create your user account.
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3">
                            <telerik:RadGrid ID="companySearchResultsGrid" runat="server" AllowFilteringByColumn="True" AllowSorting="True" GridLines="None" 
                                                AllowPaging="True" Skin="Windows7" PageSize="20" OnSelectedIndexChanged="companySearchResultsGrid_SelectedIndexChanged" AutoGenerateColumns="False">
                                <MasterTableView DataKeyNames="id" Width="100%">
                                <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
  
                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </RowIndicatorColumn>
  
                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </ExpandCollapseColumn>
  
                                <Columns>
                                    <telerik:GridButtonColumn CommandName="Select" ButtonType="ImageButton" ImageUrl="~/Images/action_check.png" HeaderStyle-Width="8px" ItemStyle-Width="8px"/>
                                    <telerik:GridBoundColumn DataField="name" FilterControlAltText="Filter By Company Name" HeaderText="Company Name" SortExpression="name" UniqueName="name">
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </MasterTableView>
  
                            <FilterMenu EnableImageSprites="False"></FilterMenu>
  
                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
  
                            </telerik:RadGrid>
                            <asp:SqlDataSource ID="companySearchResultsDS" runat="server" ConnectionString="<%$ ConnectionStrings:DADCAConnectionString %>" />
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3" align="left">
                            Don't see your company? <a href="#">Click here</a> to continue registration for a new company.
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                </table>
            </telerik:RadPageView>
            <telerik:RadPageView ID="companyDetailsView" runat="server">
                <table width="100%" align="center">
                    <tr>
                        <td> </td>
                    </tr>
                    <tr>
                        <td width="40%" align="left">
                            <img src="../Images/DaytonDefenseLogo.jpg" alt="Dayton Defense Logo" width="100%"/>
                        </td>
                        <td width="5%"></td>
                        <td align="left" valign="top">
                            <h1><asp:Label ID="results_company_header_label" runat="server"></asp:Label></h1>
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                </table>
                <table width="95%" align="center">
                    <tr>
                        <td colspan="3" align="right" width="100%">
                            <telerik:RadButton ID="backToSearchResults" runat="server" Text="Back To Company Search Results" Skin="Windows7" OnClick="backToSearchResultsButton_OnClick" />
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3" align="center" width="100%">
                            We currently have a record of your company in our database.<br /><br />
                            The point of contact (POC) for your company is:
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3" align="center">
                            POC details
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3">
                                  
                        </td>
                    </tr>
                    <tr><td> </td></tr>
                    <tr>
                        <td colspan="3" align="left">
                                  
                        </td>
                    </tr>
                </table>
            </telerik:RadPageView>
        </telerik:RadMultiPage>
        <script language="javascript" type="text/javascript">
  
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
  
            function CancelWindow() {
                var wnd = GetRadWindow();
                wnd.close();
            }
  
            function CloseWndw() {
                var wnd = GetRadWindow();
                wnd.close();
            }
  
            function Waiting(s, e) {
                Callback.PerformCallback();
                LPWaitConn.Show();
            }
  
            function RequestStart(sender, args) {
                if ($telerik.isSafari) {
                    var scrollTopOffset = document.body.scrollTop;
                    var scrollLeftOffset = document.body.scrollLeft;
                }
                else {
                    var scrollTopOffset = document.documentElement.scrollTop;
                    var scrollLeftOffset = document.documentElement.scrollLeft;
                }
  
                var loadingImageWidth = 55;
                var loadingImageHeight = 55;
  
                loadingPanel.style.backgroundPosition = (parseInt(scrollLeftOffset) + parseInt(viewportWidth / 2) - parseInt(loadingImageWidth / 2)) + "px " + (parseInt(scrollTopOffset) + parseInt(viewportHeight / 2) - parseInt(loadingImageHeight / 2)) + "px";
            }
        </script>
        <asp:Label ID="successLabel" runat="server" />
    </div>
    </form>
</body>
</html>

And this is my code-behind file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using DADCA.Authentication;
  
namespace DADCA.Account
{
    public partial class CreateAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                companySearchResultsGrid.DataSource = companySearchResultsDS;
                companySearchResultsGrid.DataBind();
            }
        }
  
        protected void RadSubmitButton_OnClick(object sender, EventArgs e)
        {
            if (companyName.Text != null && companyName.Text != "")
            {
                //Get the parameters for the query based on the company name the user gave us
                List<string> parameters = companyName.Text.Split(' ').ToList<string>();
  
                if (parameters != null && parameters.Count > 0)
                {
                    //Set the SQL query of the data source
                    string sql = "SELECT [Companies].id, [Companies].name FROM Companies WHERE ";
  
                    foreach (string p in parameters)
                    {
                        sql += "[Companies].name LIKE '%" + p + "%' OR ";
                    }
  
                    sql = sql.Substring(0, sql.Length - 4); //Trim off the last ' OR '
  
                    //Set the select command of the data source
                    companySearchResultsDS.SelectCommand = sql;
  
                    //Assign the data source and rebind
                    companySearchResultsGrid.DataSource = companySearchResultsDS;
                    companySearchResultsGrid.DataBind();
  
                    //Change to the correct page view
                    companySearchResultsView.Selected = true;
  
                    //Get rid of any errors that may be there
                    errorLabel.Visible = false;
                    asterikSpan.Visible = false;
                }
            }
            else
            {
                errorLabel.Text = "You must supply your company name to continue.";
                errorLabel.Visible = true;
                asterikSpan.Visible = true;
            }
        }
  
        protected void companySearchResultsGrid_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedCompany = companySearchResultsGrid.SelectedItems[0] as GridDataItem;
            if (selectedCompany != null)
            {
                string key = selectedCompany.GetDataKeyValue("id").ToString();
  
                //Once we have the ID of the company the user selected, show them the company's details
                //along with information on how to get added as a user
                  
            }
        }
  
        protected void backToSearchButton_OnClick(object sender, EventArgs e)
        {
            //Make sure we aren't showing any errors when we go back
            errorLabel.Visible = false;
            asterikSpan.Visible = false;
            companySearchView.Selected = true;
        }
  
        protected void backToSearchResultsButton_OnClick(object sender, EventArgs e)
        {
  
        }
  
    }
}

I have absolutely no idea what I'm doing wrong. I tried to rebind the grid in the page load method, but still no dice. Any ideas?

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 11 May 2011, 05:08 PM
Hi Andrew,

Simple data-binding calling DataBind() method can be used in simple cases when you do not require the grid to perform complex operations such as paging, sorting, grouping etc. In order to achieve your goal I suggest that you switch to advanced binding with NeedDataSource event handling and see whether this helps.

Kind regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Andrew
Top achievements
Rank 1
answered on 11 May 2011, 05:21 PM
I switched to using the advanced method by doing the following:

Added the onneeddatasource method

protected void companySearchResultsGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
  
{
  
companySearchResultsGrid.DataSource = companySearchResultsDS;
  
}

Changed the initial binding from .DataBind() to .Rebind()

I'm still getting the same problem, the RadGrid simply dissapears and is not rendered.
0
Andrew
Top achievements
Rank 1
answered on 11 May 2011, 08:33 PM
Found the issue. The problem is that the SqlDataSource is given its select command dynamically in the code-behind. When the page was reloading it was taking away the select command that was dynamically assigned and loading it as:

<asp:SqlDataSource ID="companySearchResultsDS" runat="server" ConnectionString="<%$ ConnectionStrings:DADCAConnectionString %>" />

The fact that the data source does not have any select statement defined caused the RadGrid to not be rendered. Problem is solved by placing the sql string in the session and then assigning it to the data source in the page_load function if it exists.
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or