I am desiging in VS 2008, a Nested Repeater design. When building the solution, an error is thrown stating,
Error 1 Value of type 'ExampleVBNet.Repeater' cannot be converted to 'System.Web.UI.WebControls.Repeater'. C:\Practice Code\Feb_2013\ExampleVBNet\ExampleVBNet\Repeater.aspx.vb 57 66 ExampleVBNet
I am sure the error has nothing to do with the code, because the exact same code works in a separate VS 2005 project. But has failed even when i port it to a brand new 2008 project.
Here is the code behind throwing the error:
Protected Sub MasterRep_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim connectionString As String = ConfigurationManager.ConnectionStrings("2011TestDatabase").ConnectionString
Dim conn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand("SelectAllEmployeeTitle", conn)
With cmd
.CommandType = CommandType.StoredProcedure
'.Parameters.Add("@id", SqlDbType.VarChar, 100)
'.Parameters("@pdata").Value = "Whatever"
End With
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataSource = ds.Tables("Table")
CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataTextField = "title"
CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataValueField = "id"
CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataBind()
' Find and populate nested reader
Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
Error On line below when attempting assignment
Dim ChildRep As System.Web.UI.WebControls.Repeater = CType(e.Item.FindControl("ChildRep"), Repeater)
ChildRep.DataSource = drv.CreateChildView("StoreID")
ChildRep.DataBind()
End If
End Sub
This is the aspx, showing the nested repeater which is in the item template of the master repeater
I have not been able to solve this in my 2008 project. I was able to replicate it in a 2005 project, when I had more than one webform in the project which had a repeater control.
Problem is in converting one control to Repeater as an error syas :
I think you shoule try DirectCast :
Dim rpNest as Repeater=DirectCast(e.Item.FindControl("ChildRep"), Repeater)
Hope it helps.
And let me tell you one thing, your same code is running in VS2005 and not in VS2008 it is because, sometimes some methods or their type of use changes version to version, if you observe carefully you can see it while developing VS shows that messages in
tooltips.
Thank you for the reply. I have the exact same scenario when I use DirectCast to attempt to access the ChildRepeater object as a Repeater. I would be very appreciative if I could solve this.
michaelparke...
0 Points
2 Posts
Nested Repeater is identified by project name, and not as WebControls.Repeater
Feb 13, 2013 03:41 AM|LINK
I am desiging in VS 2008, a Nested Repeater design. When building the solution, an error is thrown stating,
Error 1 Value of type 'ExampleVBNet.Repeater' cannot be converted to 'System.Web.UI.WebControls.Repeater'. C:\Practice Code\Feb_2013\ExampleVBNet\ExampleVBNet\Repeater.aspx.vb 57 66 ExampleVBNet
I am sure the error has nothing to do with the code, because the exact same code works in a separate VS 2005 project. But has failed even when i port it to a brand new 2008 project.
Here is the code behind throwing the error:
Protected Sub MasterRep_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then Dim connectionString As String = ConfigurationManager.ConnectionStrings("2011TestDatabase").ConnectionString Dim conn As New SqlConnection(connectionString) Dim cmd As New SqlCommand("SelectAllEmployeeTitle", conn) With cmd .CommandType = CommandType.StoredProcedure '.Parameters.Add("@id", SqlDbType.VarChar, 100) '.Parameters("@pdata").Value = "Whatever" End With Dim da As New SqlDataAdapter(cmd) Dim ds As New DataSet da.Fill(ds) CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataSource = ds.Tables("Table") CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataTextField = "title" CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataValueField = "id" CType(e.Item.FindControl("ddlAddTitle"), DropDownList).DataBind() ' Find and populate nested reader Dim drv As DataRowView = TryCast(e.Item.DataItem, DataRowView) Error On line below when attempting assignment Dim ChildRep As System.Web.UI.WebControls.Repeater = CType(e.Item.FindControl("ChildRep"), Repeater) ChildRep.DataSource = drv.CreateChildView("StoreID") ChildRep.DataBind() End If End SubThis is the aspx, showing the nested repeater which is in the item template of the master repeater
<asp:Repeater ID="ChildRep" runat="server" OnItemDataBound="ChildRep_ItemDataBound" OnItemCommand="ChildRep_ItemCommand" > <ItemTemplate> <div style="background-color:#cccccc;"> <div style='text-align:left; float:left; width:150px; margin-left:10px;margin-top:7px;margin-bottom:7px;clear:both;'> <asp:Label ID="lblID" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "id") %>'></asp:Label> <asp:Label ID="lblStoreID" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "store_id") %>'></asp:Label> <asp:Label ID="lblFName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "first_name")%>'></asp:Label> <asp:TextBox ID="txtFName" BackColor="#d4d0c8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "first_name")%>' Visible="false"></asp:TextBox> </div> <div style='text-align:left; float:left; width:150px; margin-left:10px; margin-top:7px; margin-bottom:7px;'> <asp:Label ID="lblLName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "last_name")%>'></asp:Label> <asp:TextBox ID="txtLName" BackColor="#d4d0c8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "last_name")%>' Visible="false"></asp:TextBox> </div> <div style='text-align:left; float:left; width:150px; margin-left:10px; margin-top:7px; margin-top:7px; margin-bottom:7px;'> <asp:Label ID="lblTitleId" runat="server" visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "[title_id]")%>'></asp:Label> <asp:DropDownList ID="ddlTitle" runat="server"></asp:DropDownList> </div> <div style='text-align:left; float:left; margin-left:10px;'> <asp:LinkButton ID="lnkEdit" runat="server" CommandName="edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>'>Edit</asp:LinkButton> <asp:LinkButton Visible="false" ID="lnkUpdate" runat="server" CommandName="update" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>'>Update</asp:LinkButton> <asp:LinkButton Visible="false" ID="lnkCancel" runat="server" CommandName="cancel" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>'>Cancel</asp:LinkButton> <asp:LinkButton ID="lnkDelete" runat="server" CommandName="delete" OnClientClick='javascript:return confirm("Are you sure you want to delete?")' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>'>Delete</asp:LinkButton> </div> </div> </ItemTemplate> </asp:Repeater>I have not been able to solve this in my 2008 project. I was able to replicate it in a 2005 project, when I had more than one webform in the project which had a repeater control.
Input would be very appreciated.
Thanks
Mike
Sujeet Saste
Contributor
3016 Points
576 Posts
Re: Nested Repeater is identified by project name, and not as WebControls.Repeater
Feb 13, 2013 05:47 AM|LINK
Problem is in converting one control to Repeater as an error syas :
I think you shoule try DirectCast :
Dim rpNest as Repeater=DirectCast(e.Item.FindControl("ChildRep"), Repeater)Hope it helps.
And let me tell you one thing, your same code is running in VS2005 and not in VS2008 it is because, sometimes some methods or their type of use changes version to version, if you observe carefully you can see it while developing VS shows that messages in tooltips.
I can not describe myself clearly.
Let me know if any query remains..
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
michaelparke...
0 Points
2 Posts
Re: Nested Repeater is identified by project name, and not as WebControls.Repeater
Feb 14, 2013 02:14 AM|LINK
Thank you for the reply. I have the exact same scenario when I use DirectCast to attempt to access the ChildRepeater object as a Repeater. I would be very appreciative if I could solve this.