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

Rating in RadGrid does not show after NeedDataSource

1 Answer 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cliff Gibson
Top achievements
Rank 1
Cliff Gibson asked on 14 May 2010, 11:47 AM
Having just purchased the controls I'm putting together a RadGrid that contains one of each datatype to enable me to learn how the control works and am having an issue with the Rating control.

I have a SQL procedure which returns a dataset which is bound to a datatable in the code.  This contains HotelName, Obsolete and Rating columns at present.

I've attached the code below (except the class file which handles the data call).  When I press the button I get the hotel names and the checkbox is set correctly, however the rating control does not display.  However if I press the button again, or press the HotelName header to sort the column the rating then appears...anyone know what I'm not doing...?

Cheers
Cliff


Default.aspx

<%

 

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<%

 

@ 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>

 

 

 

<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">

 

 

 

</telerik:RadStyleSheetManager>

 

 

 

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

 

 

 

</telerik:RadScriptManager>

 

 

 

<telerik:RadSkinManager ID="RadSkinManager1" runat="server" Skin="Windows7">

 

 

 

</telerik:RadSkinManager>

 

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

 

 

<AjaxSettings>

 

 

 

<telerik:AjaxSetting AjaxControlID="Button1">

 

 

 

<UpdatedControls>

 

 

 

<telerik:AjaxUpdatedControl ControlID="RadTextBox1" />

 

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" />

 

 

 

</UpdatedControls>

 

 

 

</telerik:AjaxSetting>

 

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

 

<UpdatedControls>

 

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" />

 

 

 

</UpdatedControls>

 

 

 

</telerik:AjaxSetting>

 

 

 

</AjaxSettings>

 

 

 

</telerik:RadAjaxManager>

 

 

 

<telerik:RadTextBox ID="RadTextBox1" runat="server">

 

 

 

</telerik:RadTextBox>

 

 

 

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

 

 

 

<telerik:RadGrid

 

 

 

ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"

 

 

 

onneeddatasource="RadGrid1_NeedDataSource" Visible="False"

 

 

 

onitemdatabound="RadGrid1_ItemDataBound" AllowSorting="True">

 

 

 

<MasterTableView>

 

 

 

<RowIndicatorColumn>

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

</RowIndicatorColumn>

 

 

 

<ExpandCollapseColumn>

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

</ExpandCollapseColumn>

 

 

 

<Columns>

 

 

 

<telerik:GridTemplateColumn Visible="False">

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="lblHiddenHotelID" runat="server" Text='<%# Eval("pkHotelID") %>' style="display:none"></asp:Label>

 

 

 

<asp:Label ID="lblHiddenObsolete" runat="server" Text='<%# Eval("Obsolete") %>' style="display:none"></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn HeaderText="Hotel" SortExpression="HotelName">

 

 

 

<ItemTemplate>

 

 

 

<asp:Label ID="lblHotelName" runat="server" Text='<%# Eval("HotelName") %>'></asp:Label>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn HeaderText="Obsolete">

 

 

 

<ItemTemplate>

 

 

 

<asp:CheckBox ID="chkObsolete" runat="server"></asp:CheckBox>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

<telerik:GridTemplateColumn HeaderText="Rating">

 

 

 

<ItemTemplate>

 

 

 

<telerik:RadRating ID="RadRatingHotel" runat="server" ItemCount="5" Precision="Item"

 

 

 

Value='<%# Convert.ToDouble(Eval("Rating")) %>'>

 

 

 

</telerik:RadRating>

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

 

</telerik:RadGrid>

 

 

 

</div>

 

 

 

</form>

 

</

 

 

body>

 

</

 

 

html>

 






Default.aspx.cs

using

 

 

System;

 

using

 

 

System.Collections.Generic;
using System.Web;

 

using

 

 

System.Web.UI;

 

using

 

 

System.Web.UI.WebControls;

 

using

 

 

System.Data;

 

using

 

 

System.Data.SqlClient;

 

using

 

 

Telerik.Web.UI;

 

public

 

 

partial class _Default : System.Web.UI.Page

 

{

#region

 

 

Properties

 

 

 

string connString = System.Configuration.ConfigurationManager.ConnectionStrings["EventMgmtCS"].ToString();

 

#endregion

#region

 

 

DataTables

 

 

 

DataTable HotelSearchResults

 

{

 

 

get

 

{

 

 

SqlParameterCollection sqlParams = new SqlCommand().Parameters;

 

sqlParams.Add(

 

Napp_SQLServer.BuildSQLCommandParamater("@search_type", "Hotel Name", System.Data.SqlDbType.VarChar, System.Data.ParameterDirection.Input));

 

sqlParams.Add(

 

Napp_SQLServer.BuildSQLCommandParamater("@hotel_name", RadTextBox1.Text, System.Data.SqlDbType.VarChar, System.Data.ParameterDirection.Input));

 

 

 

DataTable dt = Napp_SQLServer.BuildDataTableWithParameters(connString, "proc_hotel_search", sqlParams);

 

 

 

return dt;

 

}

}

#endregion

 

#region

 

 

Events

 

 

 

protected void Button1_Click(object sender, EventArgs e)

 

{

RadGrid1.Visible =

 

true;

 

RadGrid1.Rebind();

}

 

 

 

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

 

{

RadGrid1.DataSource = HotelSearchResults;

}

 

 

 

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

 

{

 

 

if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item | e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem | e.Item.ItemType == Telerik.Web.UI.GridItemType.EditItem | e.Item.ItemType == Telerik.Web.UI.GridItemType.SelectedItem)

 

{

 

 

//declare all the items in the grid

 

 

 

 

Label lblHiddenObsolete = (Label)e.Item.FindControl("lblHiddenObsolete");

 

 

 

CheckBox chkObsolete = (CheckBox)e.Item.FindControl("chkObsolete");

 

 

 

if (lblHiddenObsolete.Text == "True")

 

{

chkObsolete.Checked =

 

true;

 

}

 

 

else

 

{

chkObsolete.Checked =

 

false;

 

}

}

}

#endregion

}



1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 14 May 2010, 02:40 PM
Hello Cliff,

I have answered the other support ticket started by you.
To avoid duplicate posts, please continue the communication there.

Best wishes,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Cliff Gibson
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or