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

Databinding events not firing using ITemplate

8 Answers 178 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Samantha
Top achievements
Rank 1
Samantha asked on 23 Dec 2008, 10:40 PM
I have a class implementing ITemplate for the rad rotator (inside a user control).  The InstantiateIn method is called and all of the controls are created fine.  However, the Databinding events in the implemented ITemplate class don't fire:

[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

Sort by
0
Fiko
Telerik team
answered on 26 Dec 2008, 02:12 PM
Hi Samantha,

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.
0
Samantha
Top achievements
Rank 1
answered on 29 Dec 2008, 03:28 PM
Sorry, the CreateNewsScreens is actually the CreateScreens method, I edited the names of some of the methods before posting to make them a little more generic.  The example code you attached is not in a user control. 
0
Samantha
Top achievements
Rank 1
answered on 29 Dec 2008, 04:11 PM
It appears I don't need to create the RadRotatorItem, I changed my code to be like yours, attaching the template to the whole rotator rather than an individual RadRotatorItem.  For future reference, can you dynamically create RadRotatorItems, each with a different template (dynamically)?
0
Georgi Tunev
Telerik team
answered on 30 Dec 2008, 09:51 AM
Hi Samantha,

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.
0
Samantha
Top achievements
Rank 1
answered on 30 Dec 2008, 12:09 PM
It did not work when I tried to create the RadRotatorItems programmatically (see my code above), assigning a template to each RadRotatorItem and not the RadRotator as suggested.  How do I assign a template dynamically to one RadRotatorItem?
0
Georgi Tunev
Telerik team
answered on 05 Jan 2009, 08:14 AM
Hi Samantha,

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.
0
Samantha
Top achievements
Rank 1
answered on 07 Jan 2009, 11:54 AM
That's not really answering my question - I am asking about programatically.  When I tried to assign an ItemTemplate to a RadRotatorItem, that did not work.  I had to assign them template to the RadRotator itself for the code I posted to work.  What code do I need to use (in C#) to assign a template to a RadRotatorItem and not a RadRotator?
0
Georgi Tunev
Telerik team
answered on 13 Jan 2009, 12:06 PM
Hello Samantha,

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.
Tags
Rotator
Asked by
Samantha
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Samantha
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or