i try to use userControl to display SqlDataReader data.

in the main page

  public SqlDataReader Data2;

...

 <uc1:WebUserControl ID="WebUserControl1" RData1="<%=Data2 %>" runat="server" />

and in the userControl

  Repeater1.DataSource = RData1;

        Repeater1.DataBind();



     <asp:Repeater ID="Repeater1" runat="server">    <ItemTemplate> 
 <div class="row">   <b> 
 <%#DataBinder.Eval(Container.DataItem,
 "replay_subject")%></b><br />   
 <%#DataBinder.Eval(Container.DataItem,
 "replay_text")%><hr/> </div>   
 </ItemTemplate>
      </asp:Repeater>

But i keep getting this error

Cannot create an object of type 'System.Data.SqlClient.SqlDataReader' from its string representation '<%=Data2 %>' for the 'RData1' property.

share|improve this question

1 Answer

You can't assign RData1 using that inline code on the ASPX. The compiler try to convert Data2 to a string representation in order to set the property and RData1 is expecting a SqlDataReader so it fails.

You have to assign it on the code behind like this

WebUserControl1.RData1 = Data2;
share|improve this answer
it didn't recognize WebUserControl1 object from the aspx file – Bob May 13 '10 at 14:38
@Bob: You have to assign the property on the codebehind, on the CS – Claudio Redi May 13 '10 at 15:54
i did. in the same page the <uc1:WebUserControl ID="WebUserControl1" runat="server" /> is. but it didn't recognize it. any reason? – Bob May 13 '10 at 16:41
Can you paste a little more of the ASPX? Specifically, the code around WebUserControl1 – Claudio Redi May 13 '10 at 20:11
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ask_show.aspx.cs" Inherits="Default2" %> <%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">; <html xmlns="w3.org/1999/xhtml">; <body> <div> <uc1:WebUserControl ID="WebUserControl1" runat="server" /> </div> <asp:Label ID="lbl_tags" runat="server" ></asp:Label> <br /> <asp:Label ID="lbl_reply_table" runat="server" style="color: #FF0000" ></asp:Label> – Bob May 13 '10 at 21:14
show 1 more comment

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.