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

Change the Page Size and the grid display no records

5 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ashish
Top achievements
Rank 1
Ashish asked on 30 Aug 2011, 08:53 AM
 

Hi

I am using RadGrid With Paging(Mode:NextPrevAndNumeric).

Issue:-

The Problem is when i change the Page Size From the dropdown Let's say 2 to 10. then there is no record Display even the Grid has 5 records.

This Problems has Come after I implemented the "expand/collapse images when no records" in the grid followed your tetelrik article.

If I do the, Hieararchy Load Mode="Server" or remove "expand/collapse images when no records" behaviour then it's works fine.

But I need Both feature..

I also Attached the Code and Images

 

<

 

telerik:RadGrid AutoGenerateColumns="False" ID="rgSurvey" AllowPaging="True" AllowSorting="True"

 

                AllowCustomPaging="True" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"
                AllowAutomaticDeletes="true" OnItemCommand="rgSurvey_ItemCommand" OnSortCommand="rgSurvey_SortCommand"
                OnNeedDataSource="rgSurvey_NeedDataSource" runat="server" Skin="Office2007" PageSize="20"
                ShowGroupPanel="false" ClientSettings-AllowDragToGroup="true" ClientSettings-AlowExpandCollapse="true"
                OnDetailTableDataBind="rgSurvey_DetailTableDataBind" DataMember="SurveyTemplateID"
                OnItemDataBound="rgSurvey_ItemDataBound"  OnPreRender="rgSurvey_PreRender"
                <PagerStyle Mode="NextPrevAndNumeric" />
                <MasterTableView TableLayout="Fixed" DataKeyNames="SurveyTemplateID" HierarchyDefaultExpanded="false"
                    CommandItemDisplay="None" CommandItemSettings-AddNewRecordText="Add New User" HierarchyLoadMode="Client">
                    <DetailTables>
                        <telerik:GridTableView AllowPaging="false" AllowSorting="false" >
                            <Columns>
<telerik:GridTemplateColumn UniqueName="LockUnlock" HeaderText="" HeaderStyle-Width="70"
                                        ItemStyle-HorizontalAlign="Center" ItemStyle-Width="70">
                                        <itemtemplate
                                         <asp:ImageButton ID="Image1" runat="server" OnClientClick="return checkuserlock(this);" CommandName="UnlockSurvey" /> <br />
                                         <asp:Label ID="lblLockUserName" runat="server" Text='<%# Eval("LockUserName") %>' />
                                         <asp:Label ID="lblInnerLockUserId" runat="server" Text='<%# Eval("LockUserID") %>' style="display:none;"></asp:Label>
                                       </itemtemplate>
                                       </telerik:GridTemplateColumn>                                
                                <telerik:GridBoundColumn HeaderText="Version" DataField="SurveyVersion" HeaderStyle-Width="40">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="ID" DataField="SurveyTemplateID" UniqueName="SurveyTemplateID"
                                    SortExpression="SurveyTemplateID" HeaderStyle-Width="40" />
                                <telerik:GridButtonColumn HeaderText="Title" DataTextField="SurveyName" UniqueName="SurveyName"
                                    ItemStyle-Font-Bold="false" SortExpression="SurveyName" CommandName="editcontent" />
                                <telerik:GridBoundColumn HeaderText="Created By" DataField="UserNAME">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Last Updated By" DataField="LastUpdatedUser">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Approved By" DataField="ApprovedBy">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Active Date" DataField="ActiveDate">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Termination Date" DataField="TerminationDate">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Approval Status" DataField="ApprovalStatus">
                                </telerik:GridBoundColumn>
                                 <telerik:GridBoundColumn HeaderText="" DataField="LockUserID" Visible="false">
                            </telerik:GridBoundColumn>
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                    <Columns>
<telerik:GridTemplateColumn UniqueName="LockUnlock" HeaderText="" HeaderStyle-Width="70"
                            ItemStyle-HorizontalAlign="Center" ItemStyle-Width="70">
                            <ItemTemplate>
                                <asp:ImageButton ID="Image1" runat="server" OnClientClick="return checkuserlock(this);" CommandName="UnlockSurvey"/><br />
                                <asp:Label ID="lblLockUserName" runat="server" Text='<%# Eval("LockUserName") %>' />
                                <asp:Label ID="lblLockUserId" runat="server" Text='<%# Eval("LockUserID") %>' style="display:none;"></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn HeaderText="Version" DataField="SurveyVersion" HeaderStyle-Width="40">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="ID" DataField="SurveyTemplateID" UniqueName="SurveyTemplateID"
                            SortExpression="SurveyTemplateID" HeaderStyle-Width="40" />
                        <telerik:GridButtonColumn HeaderText="Title" DataTextField="SurveyName" UniqueName="SurveyName"
                            ItemStyle-Font-Bold="true" ItemStyle-ForeColor="Red" SortExpression="SurveyName"
                            CommandName="editcontent" />
                        <telerik:GridBoundColumn HeaderText="Created By" DataField="UserNAME" SortExpression="UserNAME">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Last Updated By" DataField="LastUpdatedUser"
                            SortExpression="LastUpdatedUser">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Approved By" DataField="ApprovedBy" SortExpression="ApprovedBy">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Active Date" DataField="ActiveDate" SortExpression="ActiveDate">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Termination Date" DataField="TerminationDate"
                            SortExpression="TerminationDate">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Approval Status" DataField="ApprovalStatus"
                            SortExpression="ApprovalStatus">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="" DataField="LockUserID" Visible="false">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
  
protected override void OnLoad(EventArgs e)
        {
  
            base.OnLoad(e);
  
            if (!Page.IsPostBack)
            {
 this.rgSurvey.PageSize = 2;
  }
        }
  
 protected void rgSurvey_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                                SetSurveyContentGridDataSource();
               
                            }
        }
  
  
  
  private void SetSurveyContentGridDataSource()
        {
            int totalRecord = 0;
            this.rgSurvey.DataSource = GetSearchBySurvey(ref totalRecord);
            this.rgSurvey.VirtualItemCount = totalRecord;
                   }
  
private List<GetSearchSurveyResult_Result> GetSearchBySurvey(ref int totalRecord)
        {
            string approvalstatus = string.Empty;
            SurveyQuestionBL oSurveyCategory = new SurveyQuestionBL();
            int pageSize = this.rgSurvey.PageSize;
            string sortExpression = GetSortedColumnName("SURVEY");
            string sortDirection = GetSortedDirection("SURVEY");
  
            foreach (ListItem li in cbApprovalStatus.Items)
            {
                if (li.Selected == true)
                {
                    approvalstatus += li.Value + ",";
                }
            }
            GetSearchSurveyResult_Result obj = new GetSearchSurveyResult_Result
            {
                SurveyTemplateID = txtSurveyID.Text.Length > 0 ? Convert.ToInt32(txtSurveyID.Text) : 0,
                SurveyName = txtSurveyTitle.Text,
                SurveyScopeID = Convert.ToInt32(rblScope.SelectedValue),
                ApprovalStatusID = approvalstatus,
                ClientID = Convert.ToInt32(rblScope.SelectedValue) ==(int) Scope.ClientSpecific ? (int?)Convert.ToInt32(ddlClientList.SelectedValue) : null
  
            };
            //int pageSize = this.rgSurvey.PageSize;
            var list = oSurveyCategory.GetAllSurveyResult(pageSize, obj, rgSurvey.CurrentPageIndex, ref totalRecord, sortExpression, sortDirection);
            oSurveyCategory = null;
            return list;
  
        }
  
protected void rgSurvey_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            SurveyQuestionBL oReportingCategory = new SurveyQuestionBL();
            // int record;          
            GridDataItem parentItem = e.DetailTableView.ParentItem as GridDataItem;
            string surveyTemplateID = parentItem.GetDataKeyValue("SurveyTemplateID").ToString();
            this.rgSurvey.DataSource = oReportingCategory.GetNestedSurveyById(Convert.ToInt32(surveyTemplateID));
            //this.rgSurvey.AllowPaging = false;
  
  
        }
  
  protected void rgSurvey_PreRender(object sender, EventArgs e)
        {
            HideExpandColumnRecursive(rgSurvey.MasterTableView);
        }
        public void HideExpandColumnRecursive(GridTableView tableView)
        {
            GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
            foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
            {
                foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
                {
                    if (nestedView.Items.Count == 0)
                    {
                        TableCell cell = nestedView.ParentItem["ExpandColumn"];
                        cell.Controls[0].Visible = false;
                        nestedViewItem.Visible = false;
                    }
                    if (nestedView.HasDetailTables)
                    {
                        HideExpandColumnRecursive(nestedView);
                    }
                }
            }
        }
  
 protected void rgSurvey_SortCommand(object source, GridSortCommandEventArgs e)
        {
            // if (rblSearchType.SelectedValue == "1")
            //{
            SetSortedColumnName("SURVEY", e.CommandArgument.ToString());
            SetSortedDirection("SURVEY", e.NewSortOrder.ToString());
            BindContentSurveyGrid();
}
  protected void rgSurvey_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            Int32 SurveyId, dbResult;
            int LockUserID, Edit;
            SurveyQuestionBL oReportingCategory;
            if (e.CommandName == "editcontent")
            {
  
                oReportingCategory = new SurveyQuestionBL();
                GridDataItem item = (GridDataItem)e.Item;
                SurveyId = Convert.ToInt32(item["SurveyTemplateID"].Text);
                LockUserID = Convert.ToInt32(item["LockUserID"].Text);
  
                if (LockUserID == 0 || LockUserID == base.UserID)
                {
                    dbResult = oReportingCategory.InsertSurveyForLockUnlock(base.UserID, SurveyId);
                    Edit = 1;
                }
                else
                {
                    Edit = 2;
                }
  
                Response.Redirect("~/Survey/AddSurvey.aspx?SID=" + SurveyId + "&Edit=" + Edit, true);
  
  
  
            }
            else if (e.CommandName == "UnlockSurvey")
            {
                oReportingCategory = new SurveyQuestionBL();
                GridDataItem item = (GridDataItem)e.Item;
                SurveyId = Convert.ToInt32(item["SurveyTemplateID"].Text);
                dbResult = oReportingCategory.InsertSurveyForLockUnlock(null, SurveyId);
                rgSurvey.Rebind();
  
  
            }
            else if (e.CommandName == "ChangePageSize")
            {
                rgSurvey.PageSize = ((Telerik.Web.UI.GridPageSizeChangedEventArgs)(e)).NewPageSize;
                rgSurvey.Rebind();
            }
        }


Please Provide The Solution ASAP.

Thanks & Regards
Ashish


5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Aug 2011, 09:38 AM
Hello,

please check below link.
custom pagging in Radgrid

Thanks,
Jayesh Goyani
0
Ashish
Top achievements
Rank 1
answered on 30 Aug 2011, 11:25 AM
Hi Jayesh

First I'd like to thank you for the effort you've invested to put up in a short time.

Actually the Problem Is not With Custom Paging as i mentioned earlier as you can check also the  Attached Code.

It's Perfectly working fine If we HierarchyLoadMode="ServerOnDemand" and remove the OnPreRender="rgSurvey_PreRender" i.e remove the Prerender Event .

But If i change the HierarchyLoadMode to Client or ServerBind and put a OnPreRender Event because of Expand/Collapse images hide When there is no records then it creates a problem.

Do Let me know if i am right.

Regards,
Ashish Mittal


0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Aug 2011, 12:03 PM
Hello,

Please check below link
Hiding expand/collapse images when no records with HierarchyLoadMode = Client


Thanks,
Jayesh Goyani
0
Ashish
Top achievements
Rank 1
answered on 30 Aug 2011, 02:56 PM
Hi Jayesh,

I tried but not Success this time also . I do the same thing as you can check my posted code.

All thing is working  with Expand/collapse with my previous code .But if i changed the Page size from the dropdown then it Creates a problem.

Regards,
Ashish

0
Ashish
Top achievements
Rank 1
answered on 31 Aug 2011, 02:55 PM
Anybody can help me?
Tags
Grid
Asked by
Ashish
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Ashish
Top achievements
Rank 1
Share this question
or