468,115 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

usercontrol initialization question

hallo group!

i have a user control that using a listbox and a dataset to fill it.

usually i can give some parameters in the form of public properties to
user controls for example :

<my:MinMaxAlphaField Required="false" ID="cfCity" Label="City:"
MaxCharacters="50" MinCharacters="3" runat="server"/>

so here im setting the label text and it works fine.

now for the usercontrol that has the listbox i want to pass the dataset.

unfortunately i seem to be able to just pass strings there so my
question is, how can i pass a dataset from outside?

the dataset itself is the result of a methodcall.

the page containing all this is using a wizard control and the data
depends on a wizard step before, so i tried to pass the dataset in the
wizardstep event, but this assignment seems to be done after the control
is rendered, cause if i set a breakpoint in the control's page_load
event where the dataset is assigned to the listbox its still null.

how can i accomplish my mission? i hope its understandable.

cheers

florian
Oct 21 '08 #1
1 998
Good evening,

1. Programatic data binding:
Add new property called i.e. MyListDataSource and a method:

public object MyListDataSource
{
get
{
return myListBox.DataSource;
}
set
{
myListBox.DataSource = value;
}
}

public void MyListDataBind()
{
myListBox.DataBind();
}

finally, in code behind of the page you placed your control:

cfCity.DataSource = myDataSet;
cfCity.DataBind();

2. Declarative data binding.
If you are planning to use any of the data source control (SqlDataSource,
ObjectDataSource, etc) add one additional property:

public string MyListDataSourceID
{
get
{
return myListBox.DataSourceID;
}
set
{
myListBox.DataSourceID = value;
}
}

<my:MinMaxAlphaField Required="false" ID="cfCity" Label="City:"
MaxCharacters="50" MinCharacters="3" runat="server"
MyListDataSourceID="mySqlDataSource" />

I would implement both options to give user control users a choice.

Hope this helps
--
Milosz
"Florian Paulus" wrote:
hallo group!

i have a user control that using a listbox and a dataset to fill it.

usually i can give some parameters in the form of public properties to
user controls for example :

<my:MinMaxAlphaField Required="false" ID="cfCity" Label="City:"
MaxCharacters="50" MinCharacters="3" runat="server"/>

so here im setting the label text and it works fine.

now for the usercontrol that has the listbox i want to pass the dataset.

unfortunately i seem to be able to just pass strings there so my
question is, how can i pass a dataset from outside?

the dataset itself is the result of a methodcall.

the page containing all this is using a wizard control and the data
depends on a wizard step before, so i tried to pass the dataset in the
wizardstep event, but this assignment seems to be done after the control
is rendered, cause if i set a breakpoint in the control's page_load
event where the dataset is assigned to the listbox its still null.

how can i accomplish my mission? i hope its understandable.

cheers

florian
Oct 21 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Javaman59 | last post: by
1 post views Thread by | last post: by
4 posts views Thread by Harry | last post: by
reply views Thread by Gary Shell | last post: by
1 post views Thread by Giovanni | last post: by
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.