[code]
<
telerik:RadRotator ID="radRotateNews" runat="server"
Skin="Vista"
ScrollDuration="3000" FrameDuration="2000" RotatorType="FromCode"
Width="470px" Height="312px" CssClass="RadRotator_Default"
AppendDataBoundItems="true" >
</
telerik:RadRotator>
protected
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = GetScreens();
radRotateNews.DataSource = dt;
CreateNewsScreens(dt);
radRotateNews.DataBind();
}
}
protected
void CreateScreens(DataTable dt)
{
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string screenType = dt.Rows[i]["ScreenTypeDesc"].ToString();
RadRotatorItem newsScreen = new RadRotatorItem();
newsScreen.ItemTemplate =
new NewsRotatorTemplate(screenType, dt.Rows.Count);
radRotateNews.Items.Add(newsScreen);
}
}
else
{
//show a default screen/image
}
}
public
class NewsRotatorTemplate : ITemplate
{
private string templateType;
private int numberScreens;
public NewsRotatorTemplate(string screenType, int noScreens)
{
//
// TODO: Add constructor logic here
//
this.templateType = screenType;
this.numberScreens = noScreens;
}
public void InstantiateIn(Control container)
{
....
Label
lblScreenNo = new Label();
lblScreenNo.ID =
"lblScreenNo" + screenNo;
lblScreenNo.DataBinding +=
new EventHandler(lblScreenNo_DataBinding);
container.Controls.Add(lblScreenNo);
....
}
void
lblScreenNo_DataBinding(object sender, EventArgs e)
{
Label lblScreenNo = (Label)sender;
RadRotatorItem container = (RadRotatorItem)lblScreenNo.NamingContainer;
string fieldValue = DataBinder.Eval(container.DataItem, "ScreenNo").ToString();
lblScreenNo.Text = fieldValue;
}
[/code]
Any ideas?
8 Answers, 1 is accepted
I tried to replicate your logic and to built-up a sample test demo but I was not able to this because the functions GetScreens() and CreateNewsScreens() are missing.
I am not quite sure that I completely understand your scenario but for your convenience I prepared a sample project which demonstrates how the RadRotator control can be programmatically binded to a DataTable data source and set to it a custom ItemTemplate.
Please examine my project and if you still have problems, modify it according to your setup, open a new support ticket and send it back to us. Once we have a better understanding of your requirements, we will do our best to help.
All the best,
Fiko
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.


Yes, this is possible - the template concept that is used in RadRotator is the ASP.NET's one. Basically whatever you can do with a standard template control like asp:repeater is possible with RadRotator as well.
More information on how to work with ASP.NET templates is available in many resources in the Net. For example you can check these links:
http://msdn.microsoft.com/en-us/magazine/cc301573.aspx
http://msdn.microsoft.com/en-us/library/y0h809ak(VS.71).aspx
Regards,
Georgi Tunev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

I am sorry if my answer was not precise enough - I meant to provide a general information on RadRotator's basics.
What I tried to explain is that RadRotator's databinding logic is not custom but we are using the general ASP.NET one - whatever is possible in ASP.NET when working with templates, is possible with RadRotator as well.
This being said, I suggest to implement the desired logic not by using RadRotator, but a standard asp:repeater control. Once you have your code working as expected, the same approach will work with RadRotator as well.
Regards,
Georgi Tunev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

This task is not directly related to the RadRotator control. As we pointed out the templates and the binding mechanism of RadRotator are identical with asp:repeater ones - they are the both using the framework's logic. Again we suggest to implement the desired behavior by using a repeater. Once you have your logic working as expected - just send it to us in a support ticket and we will rework it so it uses RadRotator.
Sincerely yours,
Georgi Tunev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.