日期:2014-05-18  浏览次数:20476 次

GridView编程创建模版,编辑状态不能保持!
前台:
<%@   Page   Language= "C# "   AutoEventWireup= "true "   CodeFile= "Default2.aspx.cs "   Inherits= "Default2 "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> 无标题页 </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                        <asp:GridView   ID= "GridView2 "     runat= "server "   OnRowEditing= "GridView2_RowEditing "   >
                        <Columns>
                                <asp:CommandField     ShowEditButton= "True "     />                          
                        </Columns>
                        <EditRowStyle   Width= "60px "   />
               
                </asp:GridView>
                <asp:Button   ID= "Button1 "   runat= "server "   Text= "Button "   /> </div>
        </form>
</body>
</html>


后台:

using   System;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;

public   partial   class   Default2   :   System.Web.UI.Page
{
        DataTable   dt   =   new   DataTable();
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                if   (!IsPostBack)
                {
                        CreatedGridView();
                }

                if   (Session[ "sample "]   !=   null)
                {
                        GridView2.DataSource   =   ((DataTable)Session[ "sample "]).DefaultView;
                &nbs