Passing a datatable to a web user control

  • Thread starter Thread starter mazdotnet
  • Start date Start date
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
 
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
 
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
 
Back
Top