开发者

Databinding in ASP.NET User Control

开发者 https://www.devze.com 2022-12-31 19:44 出处:网络
What is the best way to create a data bound ASP.NET user control? Ihave a user control that contains a drop down list and three label co开发者_如何学Gontrols. I would like to data bind the drop down

What is the best way to create a data bound ASP.NET user control?

I have a user control that contains a drop down list and three label co开发者_如何学Gontrols. I would like to data bind the drop down list, and have the label controls display different properties of the data source.

I have Googled for an example of IDataSource and User Control, but cannot find any good information. This must be a common use of a user control?


The most straightforward approach is to add Bind(data) method to user control that delegates data to inner controls and do whatever you want. For example implementation may set DropDownList.DataSource property and then call DropDownList.DataBind... This approach may be used from any webpage processing stage (page_load, page_init, another control event handler...) and gives clear workflow to me. You always know when data is bound.

Another option is to override DataBind method and rely on standard asp.net webpage processing workflow.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号