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

Expanding MasterTableView Items from Server Side causes Paging Footer section to always visible

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Golden
Top achievements
Rank 1
Golden asked on 02 Sep 2008, 11:51 PM

I want to expand all Master Table View Items from code behind (server side). To do this, I use Page_PreRenderComplete() event and expanding each MasterTableView Items.
It works fine, however for some reason the Paging Footer section is always visible. I want the Paging Footer to only appear if the number of records are bigger than the Page Size.
If you manually expand an item from UI, the Grid behaves correctly.

Telerik version used: Version=2008.2.826.35
Environment: Visual Studi0 2008 with .NET Framework 3.5


<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadGridTest.aspx.cs" Inherits="SlidingPaneTest.RadGridTest" %>

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title></title>

</

head>

<

body>

<form id="form1" runat="server">

<div>

<asp:CheckBox ID="chkShowAll" runat="server" AutoPostBack="true" Text="Expand All"

OnCheckedChanged="chkShowAll_CheckedChanged" />

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">

</telerik:RadScriptManager>

<telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="True" AllowPaging="true"

ShowGroupFooter="false" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"

Skin="Office2007" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" PageSize="20">

<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>

<MasterTableView Width="100%" AutoGenerateColumns="False" DataKeyNames="MasterID"

Name="MasterTable">

<DetailTables>

<telerik:GridTableView Width="1000" runat="server" AutoGenerateColumns="False" Name="DetailView"

ShowStatusBar="False" PageSize="10" EditMode="EditForms">

<PagerStyle Mode="NumericPages" AlwaysVisible="false" />

<Columns>

<telerik:GridBoundColumn SortExpression="Hobby" DataField="Hobby" UniqueName="Hobby"

HeaderText="Hobby" HeaderButtonType="TextButton" />

</Columns>

</telerik:GridTableView>

</DetailTables>

<Columns>

<telerik:GridBoundColumn SortExpression="Name" DataField="Name" HeaderText="Name"

UniqueName="Name" HeaderButtonType="TextButton">

</telerik:GridBoundColumn>

</Columns>

</MasterTableView>

</telerik:RadGrid>

</div>

</form>

</

body>

</

html>


using

System;

using

System.Collections.Generic;

using

System.Linq;

using

System.Web;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Data;

using

Telerik.Web.UI;

namespace

SlidingPaneTest

{

public partial class RadGridTest : System.Web.UI.Page

{

protected void Page_PreRenderComplete(object sender, EventArgs e)

{

if (chkShowAll.Checked)

{

foreach (GridItem item in RadGrid1.MasterTableView.GetItems(GridItemType.Item))

{

item.Expanded = true;

}

foreach (GridItem item in RadGrid1.MasterTableView.GetItems(GridItemType.AlternatingItem))

{

item.Expanded = true;

}

}

}

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

RadGrid1.DataBind();

}

}

private DataTable CreateMasterTable()

{

DataTable dt = new DataTable();

dt.Columns.Add("MasterID");

dt.Columns.Add("Name");

DataRow dr;

dr = dt.NewRow();

dr[0] = "1";

dr[1] = "John Smith";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[0] = "2";

dr[1] = "William Bush";

dt.Rows.Add(dr);

 

dr = dt.NewRow();

dr[0] = "3";

dr[1] = "Andrew Connection";

dt.Rows.Add(dr);

return dt;

}

private DataTable GetHobby()

{

DataTable dt = new DataTable();

dt.Columns.Add("Hobby");

DataRow dr;

dr = dt.NewRow();

dr[0] = "Swimming";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[0] = "Reading";

dt.Rows.Add(dr);

return dt;

}

private void SetDataSource()

{

if (Session["MasterData"] == null)

{

Session["MasterData"] = CreateMasterTable();

}

RadGrid1.DataSource = Session["MasterData"];

}

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

{

if (!e.IsFromDetailTable)

{

SetDataSource();

}

}

 

 

protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)

{

GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;

switch (e.DetailTableView.Name)

{

case "DetailView":

{

string id = dataItem.GetDataKeyValue("MasterID").ToString();

e.DetailTableView.DataSource = GetHobby();

break;

}

}

}

protected void chkShowAll_CheckedChanged(object sender, EventArgs e)

{

RadGrid1.Rebind();

}

}

}

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 04 Sep 2008, 12:09 PM
Hello Golden,

Using RadGrid's PreRender event for this functionality, instead of Page_PreRender, should successfully fix the problem, as RadGrid cannot properly modify its item state in Page_PreRender. Please check it out.

Kind regards,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Golden
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or