Passing a datatable to a web user control

M

mazdotnet

Hi all,

I'm working on a page with multiple web user controls. One to display
the categories another to display the data. I use a single stored
procedure to return 2 datatables. Now on my page I have 2 web user
controls. One to display the categories another to display the
downloads. I know how to send static parameters e.g., "123" to web
user controls. But how do you send dynamic values such as a dataset.

Let's say I have the DataTable myCategories and I want to send it in

<uc2:MyUserControl ID="MyCategoriesUserControl1"
runat="server" CategoryDataTable="how do you declare it
here ???????" TotalRows="5" />

Thanks
Maz
 
M

Mark Fitzpatrick

You can do it in code pretty easily if you make the DataTable in the control
a property that you can set. Then in the Load event of the page, set the
property on the control.

In the control you could have

public DataTable CategoryDataTable
{
get
{
if(ViewState["CategoryDataTable"] != null)
return (DataTable)ViewState["CategoryDataTable"];
else
return null;
}
set {ViewState["CategoryDataTable"] = value;}
}

Then you could just reference it as this.CategoryDataTable in the control

In the page you would reference it as
MyCategoriesUserControl1.CategoryDataTable;

The way I do it here will store the datatable in the viewstate so it doesn't
have to be set every time, but if you don't want it in the viewstate you
could get and set it to a local, private field in the web user control.

Hope this helps,
Mark Fitzpatrick
 
M

mazdotnet

You can do it in code pretty easily if you make the DataTable in the control
a property that you can set. Then in the Load event of the page, set the
property on the control.

In the control you could have

public DataTable CategoryDataTable
{
    get
        {
            if(ViewState["CategoryDataTable"] != null)
                return (DataTable)ViewState["CategoryDataTable"];
            else
                return null;
        }
    set {ViewState["CategoryDataTable"] = value;}

}

Then you could just reference it as this.CategoryDataTable in the control

In the page you would reference it as
MyCategoriesUserControl1.CategoryDataTable;

The way I do it here will store the datatable in the viewstate so it doesn't
have to be set every time, but if you don't want it in the viewstate you
could get and set it to a local, private field in the web user control.

Hope this helps,
Mark Fitzpatrick




I'm working on a page with multiple web user controls. One to display
the categories another to display the data. I use a single stored
procedure to return 2 datatables. Now on my page I have 2 web user
controls. One to display the categories another to display the
downloads. I know how to send static parameters e.g., "123" to web
user controls. But how do you send dynamic values such as a dataset.
Let's say I have the DataTable myCategories and I want to send it in
<uc2:MyUserControl ID="MyCategoriesUserControl1"
       runat="server"  CategoryDataTable="how do you declare it
here ???????" TotalRows="5" />
Thanks
Maz- Hide quoted text -

- Show quoted text -

Thanks
Maz
 

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,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top