在ASP.NET 3.5中使用新的ListView控件(5)
2010-11-19 11:11
387 查看
首先,你设置SqlDataSource的UpdateCommand属性,这样SQL语句就会用由用户指定的最新值执行数据库更新操作。
<asp:SqlDataSource ID="deptSource" runat="server"
ConnectionString="< ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
SelectCommand="SELECT [DepartmentID],[Name],[GroupName] FROM
HumanResources.Department" UpdateCommand="UPDATE
HumanResources.Department SET Name = @Name,
GroupName = @GroupName WHERE DepartmentID = @DepartmentID">
</asp:SqlDataSource>
接下来,在ItemTemplate组件中,指定编辑项目的连接用户:
<ItemTemplate>
----
----
<asp:LinkButton ID="btnEdit" runat="Server" Text="Edit"
CommandName="Edit" /> CommandName="Edit" />
</td>
</tr>
</ItemTemplate>
然后,指定EditItemTemplate声明用户输入更新的部门名称或组名的文本框,以及提交或取消当前操作的用户连接。
<EditItemTemplate>
<tr style="background-color: #ADD8E6">
<td>
<asp:TextBox ID="txtName" runat="server"
Text='< Text='<%# Bind("Name") %>'
MaxLength="50" /><br />
</td>
<td>
<asp:TextBox ID="txtGroupName" runat="server" Text='<%#
Bind("GroupName") %>' MaxLength="50" /><br />
</td>
<td>
<asp:LinkButton ID="btnUpdate" runat="server"
CommandName="Update" Text="Update" /> CommandName="Update" Text="Update" />
<asp:LinkButton ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" /> CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
<asp:SqlDataSource ID="deptSource" runat="server"
ConnectionString="< ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
SelectCommand="SELECT [DepartmentID],[Name],[GroupName] FROM
HumanResources.Department" UpdateCommand="UPDATE
HumanResources.Department SET Name = @Name,
GroupName = @GroupName WHERE DepartmentID = @DepartmentID">
</asp:SqlDataSource>
接下来,在ItemTemplate组件中,指定编辑项目的连接用户:
<ItemTemplate>
----
----
<asp:LinkButton ID="btnEdit" runat="Server" Text="Edit"
CommandName="Edit" /> CommandName="Edit" />
</td>
</tr>
</ItemTemplate>
然后,指定EditItemTemplate声明用户输入更新的部门名称或组名的文本框,以及提交或取消当前操作的用户连接。
<EditItemTemplate>
<tr style="background-color: #ADD8E6">
<td>
<asp:TextBox ID="txtName" runat="server"
Text='< Text='<%# Bind("Name") %>'
MaxLength="50" /><br />
</td>
<td>
<asp:TextBox ID="txtGroupName" runat="server" Text='<%#
Bind("GroupName") %>' MaxLength="50" /><br />
</td>
<td>
<asp:LinkButton ID="btnUpdate" runat="server"
CommandName="Update" Text="Update" /> CommandName="Update" Text="Update" />
<asp:LinkButton ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" /> CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
相关文章推荐
- 在ASP.NET 3.5中使用新的ListView控件(3)
- 在ASP.NET 3.5中使用新的ListView控件(4)
- 在ASP.NET 3.5中使用新的ListView控件(6)
- listview 的用法 (asp.net3.5新增控件)
- ASP.NET 3.5 的 ListView 控件与 CSS Friendly
- 关于asp.net3.5(S2008)中ajaxcontroltoolkit控件不能使用的解决办法
- asp.net中ListView控件动态绑定数据源后,使用DataPager出现错误的原因及解决办法
- asp.net中ListView控件动态绑定数据源后,使用DataPager出现错误的原因及解决办法
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(一)
- Asp.Net ListView 控件的使用
- Asp.Net ListView 控件的使用
- asp.net,关于Listview+DataPager控件使用
- listview 的用法 (asp.net3.5新增控件)
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(二)
- ASP.NET关于Login控件使用 (转)
- ASP.NET中 Calendar(日期控件)的使用
- ASP.NET使用RadioButton控件
- ASP.NET中 TextBox控件使用 ReadOnly="true" 属性
- 使用反射将业务对象绑定到 ASP.NET 窗体控件
- ASP.NET 2.0中使用webpart系列控件