您的位置:首页 > 编程语言 > ASP

在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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: