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

Invalid attempt to call FieldCount when reader is closed.

2 Answers 660 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Paul J
Top achievements
Rank 1
Paul J asked on 09 Jun 2010, 08:05 PM
keep getting:

Invalid attempt to call FieldCount when reader is closed.

calling rlv.Rebind() on page load.

<telerik:RadListView ID="rlv" OnNeedDataSource="rlv_NeedDataSource" ItemPlaceholderID="ProductItemContainer" runat="server"
            <LayoutTemplate> 
             
                <fieldset> 
                    <legend>Parent Contacts</legend> 
                    <table cellpadding="0" cellspacing="0" class="tblDisplay" width="auto"
                    <tr> 
                        <td>Name</td> 
                        <td>Relation</td> 
                        <td>Phone</td> 
                        <td>Work #</td> 
                        <td>Cell #</td> 
                    </tr> 
                    <asp:PlaceHolder ID="ProductItemContainer" runat="server" /> 
                    </table> 
                </fieldset> 
            </LayoutTemplate>             
             <ItemTemplate> 
                 <tr> 
                    <td><%#DataBinder.Eval(Container.DataItem, "FullName")%>"</td> 
                    <td><%#DataBinder.Eval(Container.DataItem, "RelationDesc")%>"</td> 
                    <td><%#DataBinder.Eval(Container.DataItem, "Phone")%>"</td> 
                    <td><%#DataBinder.Eval(Container.DataItem, "WorkPhone")%>"</td> 
                    <td><%#DataBinder.Eval(Container.DataItem, "CellPhone")%>"</td> 
                 </tr> 
            </ItemTemplate>             
            </telerik:RadListView> 

.List() below returns a datareader.
        Protected Sub rlv_NeedDataSource(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadListViewNeedDataSourceEventArgs) Handles rlv.NeedDataSource 
 
            Dim sqlDR As SqlDataReader 
            sqlDR = ObjectTest.List() 
            rlv.DataSource = sqlDR 
        End Sub 





2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Jun 2010, 04:06 PM
Hello Paul,

Can you please verify that neither the DataReader nor the underlining DataConnection is closed while RadListView is databinding. The best place to close the connection and reader in this case will be inside RadListView DataBound event. You may take a look at this online demo for a runnable sample.

Sincerely yours,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Paul J
Top achievements
Rank 1
answered on 16 Jun 2010, 09:43 PM
Thanks, That was the problem. My ObjectTest.List() returns a sqldatareader. This .List() function exists within a business class. Because of this setup, I guess the sqldatareader the .List() function returns gets closed after the list control binds to it? and binding that to a radListView doesn't allow me to close the sqldatareader within the list's databind event instead.

I had to change the code so that instead of binding it to the object class's .List function, I had to create a different sqldatareader, loading it , etc. on the same code level as where I bind the list to the sqldatareader, so I have direct access to this reader in the radListView's databind event to close the sqldatareader. For cleaniless of code, I'd rather not do this. I'm not sure why the radListview has an issue with binding to my object class's .List function when the radGrid doesn't. So I ended up using a radGrid for what I need instead of the radListView.

Thanks though...
Tags
ListView
Asked by
Paul J
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Paul J
Top achievements
Rank 1
Share this question
or