How to use user control's property of DataTable type

I

IKdev

I have a user control (not custom control) and want to use a public property
of it which is of DataTable type.
contol is used in the page in this manner:
<uc1:Mover id="MoverFFF" runat="server"
OriginalData='<%MyAssembly.MyClass.GetMyData("FFF")%>'>
I got error : "Cannot create an object of type 'System.Data.DataTable' from
its string representation '<%MyAssembly...."
Note: MyAssembly.MyClass.GetMyData is static method of a DataTable type

The property definition:

public DataTable OriginalData
{
get
{ return lstOriginal.DataSource as DataTable;}
set
{ lstOriginal.DataSource=value;
lstOriginal.DataValueField="ID";
lstOriginal.DataTextField="text";
lstOriginal.DataBind();
}
}

Please help!

Best regards,
IK
 
J

Jorge Matos

IKdev,

When you use the declarative form to initialize properties of a server
control, you must work with string properties. That's why the error says
"Cannot create... from its string representation".

Try setting the "OriginalData" property from the web form's code-behind or
from a server-side script block instead.

<script runat="server" language="C#">
void page_load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MoverFFF.OriginalData = MyAssembly.MyClass.GetMyData("FFF");
}
}
</script>

hth
Jorge
 
I

IKdev

Thank you! I just did not realize I could access user control in the code
behind since ASP.NET does not create a property (protected
MyWebApp.Controls.Mover MoverFFF) for the user control once it is placed on
the page, contrary to custom control placement. I thought it is by design
because user control is declared as abstract class. Anyway, thanks for
pointing me in the right direction.

Best regards,
IK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top