扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
public class WeatherDataSource : DataSourceControl { public static readonly string ZipCodeParameterName = "ZipCode"; ... private ParameterCollection _parameters; private ParameterCollection Parameters { get { if (_parameters == null) { _parameters = new ParameterCollection(); _parameters.ParametersChanged += new EventHandler(this.OnParametersChanged); if (IsTrackingViewState) { ((IStateManager)_parameters).TrackViewState(); } } return _parameters; } } ... public string GetSelectedZipCode() { if (_parameters != null) { Parameter zipCodeParameter = _parameters[ZipCodeParameterName]; if (zipCodeParameter != null) { IOrderedDictionary parameterValues = _parameters.GetValues(Context, this); return (string)parameterValues[zipCodeParameter.Name]; } } return ZipCode; } protected override void LoadViewState(object state) { object baseState = null; if (state != null) { Pair p = (Pair)state; baseState = p.First; if (p.Second != null) { ((IStateManager)Parameters).LoadViewState(p.Second); } } base.LoadViewState(baseState); } protected override void OnInit(EventArgs e) { Page.LoadComplete += new EventHandler(this.OnPageLoadComplete); } private void OnPageLoadComplete(object sender, EventArgs e) { if (_parameters != null) { _parameters.UpdateValues(Context, this); } } private void OnParametersChanged(object sender, EventArgs e) { CurrentConditionsView.RaiseChangedEvent(); } protected override object SaveViewState() { object baseState = base.SaveViewState(); object parameterState = null; if (_parameters != null) { parameterState = ((IStateManager)_parameters).SaveViewState(); } if ((baseState != null) || (parameterState != null)) { return new Pair(baseState, parameterState); } return null; } protected override void TrackViewState() { base.TrackViewState(); if (_parameters != null) { ((IStateManager)_parameters).TrackViewState(); } } } |
private sealed class WeatherDataSourceView : DataSourceView { ... internal Weather GetWeather() { string zipCode = _owner.GetSelectedZipCode(); if (zipCode.Length == 0) { return null; } WeatherService weatherService = new WeatherService(zipCode); return weatherService.GetWeather(); } } |
Zip Code: <asp:TextBox runat="server" id="zipCodeTextBox" /> <asp:Button runat="server" Text="查找" /> <hr /> <asp:FormView runat="server" DataSourceID="weatherDS"> <ItemTemplate> <asp:Label runat="server" Text='<%# Eval("Temperature", "当前温度是 {0}。") %>' /> </ItemTemplate> </asp:FormView> <nk:WeatherDataSource runat="server" id="weatherDS"> <Parameters> <asp:ControlParameter Name="ZipCode" ControlID="zipCodeTextBox" /> </Parameters> </nk:WeatherDataSource> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者