Konstantin Pankov
Top achievements
Rank 1
Konstantin Pankov
asked on 05 Feb 2010, 08:46 PM
Hello.
Problem: RadGrid items not displayed after operations of sorting, filtering and paging. NeedDataSource event processed and RadGrid have data.
No problem when I'm testing project locally on ASP.NET Development Server or IIS 5.1, but occurs when IIS 7
Any ideas?
Thank you in advance for your help
P.S. I'm using Telerik RadControls for ASPNET AJAX Q1 2009
2 Answers, 1 is accepted
0
Konstantin Pankov
Top achievements
Rank 1
answered on 07 Feb 2010, 07:04 PM
Content page
| <asp:Content ContentPlaceHolderID="head" runat="server"> |
| <script language="javascript" type="text/javascript"> |
| function setRow(value) { |
| var rowID = document.getElementById('rowID'); |
| rowID.value = value; |
| document.getElementById('rowPanel').innerHTML = "ID = "+ value; |
| } |
| </script> |
| </asp:Content> |
| <asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> |
| <telerik:RadScriptManager runat="server" EnablePartialRendering="true" ScriptMode="Auto"> |
| </telerik:RadScriptManager> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| <telerik:AjaxUpdatedControl ControlID="rowID" /> |
| <telerik:AjaxUpdatedControl ControlID="row" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="treeView"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="LoadingPanel1"/> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" EnableSkinTransparency="true" BackgroundPosition="Center" |
| Skin="Vista" > |
| </telerik:RadAjaxLoadingPanel> |
| <div style="left:0%; top:0%; width:20%; position:absolute;"> |
| <telerik:RadTreeView ID="treeView" runat="server" |
| onnodeexpand="treeView_NodeExpand" onnodeclick="treeView_NodeClick" |
| Skin="Vista" > |
| </telerik:RadTreeView> |
| </div> |
| <div style="left: 20%; top:0%; width: 70%; position:absolute;"> |
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" |
| GridLines="None" AllowAutomaticUpdates="True" Skin="Vista" |
| onselectedindexchanged="RadGrid1_SelectedIndexChanged" |
| onneeddatasource="RadGrid1_NeedDataSource" > |
| <MasterTableView AutoGenerateColumns="True" BorderColor="Gray" BorderWidth="0px" |
| GridLines="None" AllowSorting=true AllowFilteringByColumn="true" AllowPaging="true" > |
| <Columns > |
| <telerik:GridTemplateColumn> |
| <ItemTemplate> |
| <input type="radio" id="test" enableviewstate="true" name="Group" onclick="setRow('<%# ((DataRowView)Container.DataItem)["ID"] %>')"/> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn></Columns> |
| </MasterTableView> |
| <ClientSettings EnablePostBackOnRowClick="true" AllowColumnsReorder="True" ReorderColumnsOnClient="True"> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| </telerik:RadGrid> |
| <div style="margin:5%; text-align:center;"> |
| <asp:Literal ID="Literal1" runat="server" Text="Файлы будут связаны с контентом: "></asp:Literal><asp:Literal runat="server" ID="row"></asp:Literal> |
| </div> |
| </div> |
| <input type="hidden" id="rowID" runat="server" value="" /> |
| </asp:Content> |
| protected DataTable GetContents(string strCommand) |
| { |
| DataTable dataTable = new DataTable(); |
| SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["quantumart"].ConnectionString); |
| try |
| { |
| sqlConnection.Open(); |
| SqlCommand sqlCommand = new SqlCommand(); |
| sqlCommand.Connection = sqlConnection; |
| sqlCommand.CommandText = strCommand; |
| SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); |
| sqlDataAdapter.Fill(dataTable); |
| } |
| catch (Exception) |
| { |
| } |
| finally |
| { |
| sqlConnection.Close(); |
| } |
| return dataTable; |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| DataTable data = GetContents("select * from Contents"); |
| foreach (DataRow dataRow in data.Rows) |
| { |
| RadTreeNode radTreeNode = new RadTreeNode(dataRow["NameOfContent"].ToString(), dataRow["ID"].ToString()); |
| radTreeNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; |
| treeView.Nodes.Add(radTreeNode); |
| } |
| } |
| } |
| protected void treeView_NodeExpand(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) |
| { |
| DataTable dataTable = GetContents(string.Format("select * from News where KindOfContentID={0}", e.Node.Value)); |
| foreach (DataRow dataRow in dataTable.Rows) |
| { |
| RadTreeNode radTreeNode = new RadTreeNode(dataRow["Title"].ToString()); |
| e.Node.Nodes.Add(radTreeNode); |
| } |
| } |
| protected void treeView_NodeClick(object sender, RadTreeNodeEventArgs e) |
| { |
| if (e.Node.Value != "") |
| { |
| DataTable dataTable = |
| GetContents(string.Format("select * from News where KindOfContentID={0}", e.Node.Value)); |
| RadGrid1.DataSource = dataTable; |
| RadGrid1.DataBind(); |
| } |
| } |
| protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| var dataRow = RadGrid1.SelectedItems[0] as GridDataItem; |
| if (dataRow!=null) |
| { |
| rowID.Value = dataRow["ID"].Text; |
| row.Text = dataRow["Title"].Text; |
| } |
| } |
| protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| if (treeView.SelectedNode!=null) |
| if (treeView.SelectedNode.Value != "") |
| { |
| DataTable dataTable = |
| GetContents(string.Format("select * from News where KindOfContentID={0}", treeView.SelectedNode.Value)); |
| RadGrid1.DataSource = dataTable; |
| } |
| } |
0
Hello Konstantin,
The reason for the behavior which you described is that the control is not properly bound to data. More precisely:
protected void treeView_NodeClick(object sender, RadTreeNodeEventArgs e)
{
if (e.Node.Value != "")
{
DataTable dataTable =
GetContents(string.Format("select * from News where KindOfContentID={0}", e.Node.Value));
RadGrid1.DataSource = dataTable;
RadGrid1.DataBind();
}
}
Setting the datasource directly, and calling databind will break the default functionalities of the control, such as filtering/sorting/paging. To populate the control with data, you need to use only NeedDataSource. Whenever you need to raise the NeedDataSource event handler again, you can call the .Rebind() method of the control. This would raise the NeedDataSource event handler, allowing you to pass the proper data to populate the control.
I hope this information helps.
Kind regards,
Yavor
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
The reason for the behavior which you described is that the control is not properly bound to data. More precisely:
protected void treeView_NodeClick(object sender, RadTreeNodeEventArgs e)
{
if (e.Node.Value != "")
{
DataTable dataTable =
GetContents(string.Format("select * from News where KindOfContentID={0}", e.Node.Value));
RadGrid1.DataSource = dataTable;
RadGrid1.DataBind();
}
}
Setting the datasource directly, and calling databind will break the default functionalities of the control, such as filtering/sorting/paging. To populate the control with data, you need to use only NeedDataSource. Whenever you need to raise the NeedDataSource event handler again, you can call the .Rebind() method of the control. This would raise the NeedDataSource event handler, allowing you to pass the proper data to populate the control.
I hope this information helps.
Kind regards,
Yavor
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.