usercontrol initialization question

F

Florian Paulus

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
 
M

Milosz Skalecki [MCAD]

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
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top