Silverlight 2 (beta1)数据操作(2)——使用ASP.NET Web Service进行数据CRUD操作(下)
2008-10-11 11:42:49 来源:WEB开发网后台代码void deleteButton_Click(object sender, RoutedEventArgs e)
整合程序
{
if (userID.Text.Trim() == string.Empty)
{
errMessage.Foreground = new SolidColorBrush(Colors.Red);
errMessage.Text = "请输入用户ID!";
errMessage.Visibility = Visibility.Visible;
return;
}
WebServiceProxy.UserManageSoapClient userMgrSoapClient =
new YJingLee.WebSrv.WebServiceProxy.UserManageSoapClient();
//调用删除方法
userMgrSoapClient.DeleteUserAsync
(Int16.Parse(userID.Text.Trim()));
userMgrSoapClient.DeleteUserCompleted+=
new EventHandler<YJingLee.WebSrv.WebServiceProxy.
DeleteUserCompletedEventArgs>
(userMgrSoapClient_DeleteUserCompleted);
}
void userMgrSoapClient_DeleteUserCompleted(object sender,
YJingLee.WebSrv.WebServiceProxy.DeleteUserCompletedEventArgs e)
{
if (e.Error == null)
{
errMessage.Text = "删除用户成功!";
errMessage.Foreground = new SolidColorBrush(Colors.Blue);
errMessage.Visibility = Visibility.Visible;
}
else
{
errMessage.Foreground = new SolidColorBrush(Colors.Red);
errMessage.Text = e.Error.ToString();
errMessage.Visibility = Visibility.Visible;
}
}
在Page.xaml页面中布局,并引入用户控件,添加4个HyperlinkButton ,单击事件用户控件在中间区域显示。例如下面一个按钮事件:
deleteCtl.Visibility = Visibility.Visible;
entryCtl.Visibility = Visibility.Collapsed;
listingCtl.Visibility = Visibility.Collapsed;
editCtl.Visibility = Visibility.Collapsed;
最终效果图如下所示:
结语
利用这个实例我们学习了在Silverlight 2中使用ASP.NET Web Service进行数据CRUD操作,这里有一些细节没有完善,比如输入框的验证问题等。下一篇我们利用ADO.NET Data Service来操作数据
Tags:Silverlight 数据
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接