简介
背后写这篇文章的目的是在实施AJAX Control Toolkit中使用。在这里,我曾尝试使用ObjectDataSource的创建一个三层架构。在应用程序中,假设我们想要做的编辑和删除客户端上的GridView行。所以在这里,我目前围绕AJAX Control Toolkit中的最简单的方法做客户端的数据修改。背景
刚才我太面临着很多问题,无法更新面板更新后如何处理任何工作。所以,我打算尽快,我有一些时间写了一个演示。请随意发表任何意见,错误或改进建议。重点方案
使用:AJAX控件工具包三层架构ObjectDataSourcenbsp;JavaScript的三层Architecturenbsp的执行情况;
现在让我们开始做的事情在一个真实的世界应用程序。创建一个数据库层名为DBClass.cs在这里我们要定义的各个领域和方法:
根据DBClass.cs类文件,创建以下:public class DBClass
{
private SqlConnection con = new SqlConnection();
private SqlCommand com = new SqlCommand();
private SqlDataAdapter da = new SqlDataAdapter();
public DBClass()
{
//
// Default Constructor
//
}
private void setConnectionState()
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.ConnectionString = ConfigurationSettings.AppSettings["sqlCon"];
con.Open();
}
public SqlCommand setCommand(string SP_Name)
{
setConnectionState();
com = new SqlCommand(SP_Name, con);
com.CommandType = System.Data.CommandType.StoredProcedure;
return com;
}
public SqlDataAdapter setAdapter(string SP_Name)
{
setConnectionState();
da = new SqlDataAdapter(SP_Name, con);
da.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
return da;
}
}
现在我们要定义的各个领域,属性和方法创建Client.cs:
Client.cs类文件下,建立以下字段:{C}AjaxComponentArtStyle.aspx
此页面包含两个更新面板。在第一次更新面板,我GridView和innbsp; secondnbsp;更新面板,我有一个DetailsView。
ASP.NET UpdatePanel控件使您能够构建丰富的,以客户为中心的Web应用程序。通过使用UpdatePanel控件,您可以刷新页的选定部分,而不是刷新整个页面回发。这被称为执行部分页更新。一个ASP.NET网页,包含一个ScriptManager控件和一个或多个UpdatePanel控件,可以自动参与部分页更新,没有自定义客户端脚本。使用ScriptManager
ScriptManager控件管理用于Microsoft ASP.NET AJAX页面的客户端脚本。默认情况下,ScriptManager控件的页面注册Microsoft AJAX Library的脚本。这使客户端脚本能够使用类型系统扩展并支持部分页呈现和Web服务调用等功能。
ObjectDataSource的<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvCustomers" runat="server" DataSourceID="odsCustomerList">
// Here we will add columns and template column fields
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
的ASP.NET ObjectDataSource控件表示一个中间层对象,数据检索和更新capabilities.The的ObjectDataSource控制行为,作为一个数据接口,如GridView,FormView的或DetailsView控件的数据绑定控件。您可以使用这些控件来显示和编辑中间层业务对象从ASP.NET网页上的数据。
在这里,我花了两个ObjectDataSource来填充GridView和为的DetailsView:
ModalPopupExtender<asp:ObjectDataSource ID="odsCustomerList" runat="server" TypeName="Client"
SelectMethod="GetAllClient" DeleteMethod="ClientDelete">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsCustomerDetail" runat="server" TypeName="Client"
DataObjectTypeName="Client" OnSelecting="OdsCustomerDetail_Selecting"
SelectMethod="ClientLoadByID" UpdateMethod="ClientUpdate">
</asp:ObjectDataSource>
弹出一个模式窗体,无论你想看到屏幕上,提示用户执行某些操作。
DetailsViewnbsp;<ajax:ModalPopupExtender ID="mdlPopup" runat="server"
TargetControlID="btnShowPopup"
PopupControlID="pnlPopup" CancelControlID="btnClose"
BackgroundCssClass="modalBackground" />
DetailsView控件显示一个从数据源,其中每个数据行表示记录中的一个领域的单个记录。它往往是一个主/详细方案中的GridView控件结合使用。
进度条<asp:DetailsView ID="dvCustomerDetail" runat="server"
DataSourceID="odsCustomerDetail" CssClass="detailgrid"
GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
Visible="false" Width="100%">
<Fields>
// Here we will add Bound field and template field to edit a row
</Fields>
</asp:DetailsView>
使用代码 <ajax:UpdatePanelAnimationExtender ID="UPAnimation" runat="server"
TargetControlID="updatePanel">
<Animations>
<OnUpdating>
<Parallel duration="0">
<%-- place the update progress div over the
gridview control --%>
<ScriptAction Script="onUpdating();" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel duration="0">
<%--find the update progress div and place it
over the gridview control--%>
<ScriptAction Script="onUpdated();" />
</Parallel>
</OnUpdated>
</Animations>
</ajax:UpdatePanelAnimationExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="progress_bar"
style="display:none;">
<div class="container">
<div class="header"> Loading, please wait...</div>
<div class="body"><br />
<img src="Images/Indicater.gif" />
</div>
</div>
</asp:Panel>
使用此代码,下载thenbsp;相关的zip文件,并创建一个数据库名为AjaxDB和运行thenbsp;在that.nbsp脚本,然后创建一个应用程序的虚拟目录,并在web.config中改变你的服务器,如下所示如下:
历史 <appSettings>
<add key="sqlCon"
value="data source=SARFARAZ-0923B2\SQLEXPRESS;initial catalog=AjaxDB;
integrated security=True"/>
</appSettings>
第五年3月,2009年:战后初期
作者简介
与Ashish辛格Parihar从IPS学院,印度中央邦印多尔,计算机应用硕士。目前他正在一个S / W公司在印多尔作为一个团队领导1年以上。他hasnbsp ofnbsp 2年以上;经验。他还完成本科学位理学士(PCM)。他喜欢与微软技术合作。他已经与C,则C瞪大了眼睛,然后转移到的。NET 1.1和。NET 2.0中。他目前正在与C#,ASP.NET,企业应用程序块,Active Directory中,WSS(Windows SharePoint服务器的),DotNetNuke的。他喜欢在C#编程。他也是微软金牌认证Web开发技术专家。他的爱好includenbsp;听音乐和发展自己的小工具和实用程序。