Hi,
I'm trying to use a WebDropDown with templated dropdown items. I need to do everything server side.
I used the following posts I found in Infragistics Help concerning the templates as a base :
http://samples.infragistics.com/2009.1/WebFeatureBrowser/srcview.aspx?path=WebDropDown/WebDropDownTemplates.src(using tables and labels in the template)
http://help.infragistics.com/NetAdvantage/ASPNET/2010.1/CLR3.5/?page=WebDropDown_Create_a_Multi_Column_WebDropDown_using_Templates.html(creating a template Server Side)
Now, I can't use the late bound method of the first post to bind my data to the labels, so I went with using the "ItemBound" event of the WebDropDown to do the job. And that's when I start to get issues.
When the ItemBound event gets fired, it seems that the ItemTemplate haven't been initiated for the item. I try to access the controls in the row with the following code in the event (assuming one of my labels has an ID of "Label1" in my template):
((Label)((DropDownItem)e.Value).FindControl("Label1")).Text = "dummy"
I get a "Object not set to an instance..." doing that. Am I doing something wrong?
Regards,
Eric B.
Seems like I found the solution myself. Or at least I found a way to get this to work.
You need to call the EnsureTemplate() function on the list item before trying to access the label in the ItemBound event of the dropdown.
Here is an small code example:
void myWebDropDown_ItemBound(object sender, DropDownItemBoundEventArgs e) {Infragistics.Web.UI.ListControls.ListItem myItem = (Infragistics.Web.UI.ListControls.ListItem)e.Value;// This is what makes the template workmyItem.EnsureTemplate();Label myLabel = (Label)myItem.FindControl("myLabel");myLabel.Text = "Some text";}
Now I wonder why isn't EnsureTemplate() being called by the control itself somewhere before the ItemBound event?
I Hope that this will be of some help to someone else.
I forgot to add that I'm using NetAdvantage 2010.3 with the latest service release (2105)