Thursday, January 28, 2010

edit all GridView rows once

Practical projects in peacetime, in order to reduce round-trip to submit data, you can edit the GridView once all the rows, thereby greatly enhancing the user experience using the product. Here's what one editor to explain all the data in GridView row. In the following example, the database using the "ASP.NET 2.0 application development technology," a book Site \ App_Data \ under ASPNET20Book.mdb database. Examples of the data update the data source use SqlDataSource control's UpdateCommand property, but this method also applies to stored procedures, SQL statements and so on.

C#
<%@ Page Language="C#" Debug="true" %>





同时编辑 GridView的 多行



DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"
OnRowCreated="GridView1_RowCreated">























ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ASPNET20Book.mdb;Persist Security Info=True"
ProviderName="System.Data.OleDb" SelectCommand="SELECT * FROM [Student]"
UpdateCommand="Update [Student] Set Title = @Title,Gender = @Gender,ClassName=@ClassName Where id=@id">







Note: For SQL Server databases, parameter names without @. Another Note: The different database types and different data sources, UpdateCommand = "Update [Student] Set Title = @ Title, Gender = @ Gender, ClassName = @ ClassName Where id = @ id" written and SqlDataSource1.UpdateParameters.Add (new Parameter ( "@ Title", TypeCode.String, ((TextBox) gvr.FindControl ( "txtTitle")). Text)); the wording may differ.

SQL Server Version

<%@ Page Language="C#" Debug="true" %>





同时编辑 GridView的 多行



DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"
OnRowCreated="GridView1_RowCreated">























ConnectionString="Persist Security Info=False;User ID=sa;Password=;Initial Catalog=Book;Server=."
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Student]"
UpdateCommand="Update [Student] Set Title = @Title,Gender = @Gender,ClassName=@ClassName Where id=@id">





No comments:

Post a Comment