Saturday, March 24, 2012

Invalid Cast Exception on DynamicPopulateExtender

Hi

I have a DynamicPopulateExtender nested within a repeater control, which is in turn populated from a code behind class. When the DynamicPopulateExtender fires, I get an invalid cast exception:

" Unable to cast object of type 'ASP.gallery_aspx' to type 'System.Web.UI.WebControls.RepeaterItem'. "

This is being caused by the dynamic context key - I've tried passing a literal string and it works. Any suggestions? Here's the code:

In 'gallery.aspx'

<script runat="server">

<System.Web.Services.WebMethod()> _
Public Function GetSinglePhoto(ByVal ContextKey As String) As String


Dim sbHTML As New StringBuilder

sbHTML.Append("<img src="http://pics.10026.com/?src=)
sbHTML.Append(Chr(34))
sbHTML.Append("photos/")
sbHTML.Append(ContextKey)
sbHTML.Append(Chr(34))
sbHTML.Append(" />")

Return sbHTML.ToString

End Function

</script>

...............

then

.................

<asp:Panel runat="server" ID="thumbnails">
<asp:Repeater ID="repGallery" runat="server">


<ItemTemplate>


<img src="http://pics.10026.com/?src=<%#DataBinder.Eval(Container.DataItem, "ImageFile")%>"Alt="<%#DataBinder.Eval(Container.DataItem, "AltText")%>"class="gallery"/>


<atlasToolkit:DynamicPopulateExtender ID="dp" runat="server">
<atlasToolkit:DynamicPopulateProperties
TargetControlID="mainpic"
PopulateTriggerControlID="thumbnails"
ServiceMethod="GetSinglePhoto"
ContextKey='<%#DataBinder.Eval(Container.DataItem, "ImageFile")%>'
UpdatingCssClass="dynamicPopulate_Updating" />
</atlasToolkit:DynamicPopulateExtender>


</ItemTemplate>
</asp:Repeater>
</asp:Panel>

............

and method to poulate repeater, in the code behind

...............

Private Sub GetPhotos()
Dim dv As DataView = _
CType(sdsGallery.Select(DataSourceSelectArguments.Empty), DataView)

For Each drv As DataRowView In dv
drv("ImageFile") = ConfigurationManager.AppSettings("GalleryFolder") & drv("ImageFile")
Next

repGallery.DataSource = dv
repGallery.DataBind()
End Sub

Please reply with acomplete, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

No comments:

Post a Comment