contentplaceholder-gridview 放在ContentPlaceHolder下,不能更新

问题描述

gridview 放在ContentPlaceHolder下,不能更新

gridview 放在ContentPlaceHolder下,为什么点击编辑后的修改,再单击更新后,连Gridview都不显示了。而单独页面就没有任何问题
前台:
<%@ Page Title="MastPage" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="Custmor.aspx.vb" Inherits="CRM_Seetop.Custmor" %>

<asp:Panel ID="Panel1" runat="server" Visible="True">
  <div style="height:30px;text-align:center ">
                    <span style="color: #FF3300">签约客户</span> <span style="color: #0033CC">管理</span>系统!
  </div>
 <div>
    <asp:GridView ID="gvCustmor" runat="server" AutoGenerateColumns="False" DataKeyNames="KID" BackColor="White"
    BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
        onpageindexchanging="gvCustmor_PageIndexChanging"
        onrowcancelingedit="gvCustmor_RowCancelingEdit"
        onrowdatabound="gvCustmor_RowDataBound" onrowdeleting="gvCustmor_RowDeleting"
        onrowediting="gvCustmor_RowEditing" onrowupdating="gvCustmor_RowUpdating"
        onsorting="gvCustmor_Sorting">
    <RowStyle BackColor="White" ForeColor="#003399" />
        <Columns>
            <asp:CommandField HeaderText="编辑" ShowEditButton="True" />
            <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
            <asp:BoundField DataField="KID" HeaderText="KID" ReadOnly="True"
                SortExpression="KID" />
            <asp:TemplateField HeaderText="简称" SortExpression="简称">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("简称")%>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("简称")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ComAbbr" SortExpression="ComAbbr">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ComAbbr")%>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("ComAbbr")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
    </asp:GridView>
       </div>

/asp:Content

后台代码:
Imports System.Data.SqlClient
Public Class Custmor
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           If Not IsPostBack Then
                  gvCustmor.AllowPaging = True
                   gvCustmor.PageSize = 15

        gvCustmor.AllowSorting = True

        ViewState("SortExpression") = "KID ASC"

        ' Populate the GridView.
        bind()
    End If

End Sub
Public Sub bind()
    Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServices").ToString())
        ' Create a DataSet object.
        Dim dsCustmor As New DataSet()
        Dim uN As String = ""
        If Session("username") Is Nothing Then
            uN = Page.User.Identity.Name
        Else
            uN = Session("username")
        End If

        Dim strSelectCmd As String = "SELECT KID,简称,ComAbbr,公司名称,CompanyName,Web,总机电话,直线电话,公司传真,产品分类,保护状态 FROM kData WHERE (负责业务='" + uN + "')"

        Dim da As New SqlDataAdapter(strSelectCmd, conn)

        conn.Open()

        da.Fill(dsCustmor, "Custmor")

        Dim dvCustmor As DataView = dsCustmor.Tables("Custmor").DefaultView

        dvCustmor.Sort = ViewState("SortExpression").ToString()

        gvCustmor.DataSource = dvCustmor
        gvCustmor.DataBind()
    End Using

End Sub

Protected Sub gvCustmor_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    ' Make sure the current GridViewRow is a data row.
    If e.Row.RowType = DataControlRowType.DataRow Then

        If e.Row.RowState = DataControlRowState.Normal OrElse e.Row.RowState = DataControlRowState.Alternate Then
            ' Add client-side confirmation when deleting.
            DirectCast(e.Row.Cells(1).Controls(0), LinkButton).Attributes("onclick") = "if(!confirm('Are you certain you want to delete this person ?')) return false;"
        End If
    End If
    If gvCustmor.Visible = False Then
        Panel1.Visible = True
        gvCustmor.Visible = True
    End If
End Sub

 Protected Sub gvCustmor_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)

    gvCustmor.PageIndex = e.NewPageIndex

        bind()
End Sub

Protected Sub gvCustmor_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)

    gvCustmor.EditIndex = e.NewEditIndex

    bind()

End Sub

Protected Sub gvCustmor_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)

    gvCustmor.EditIndex = -1

    bind()
      End Sub

Protected Sub gvCustmor_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("SQLServer2005DBConnectionString").ToString())

        Dim cmd As New SqlCommand()

        cmd.Connection = conn

        cmd.CommandText = "UPDATE kData SET 简称 = @LastName, ComAbbr = @FirstName WHERE KID = @KID"

            cmd.CommandType = CommandType.Text

        Dim strKID As String = gvCustmor.Rows(e.RowIndex).Cells(2).Text
        Dim strLastName As String = DirectCast(gvCustmor.Rows(e.RowIndex).FindControl("TextBox1"), TextBox).Text
        Dim strFirstName As String = DirectCast(gvCustmor.Rows(e.RowIndex).FindControl("TextBox2"), TextBox).Text

        cmd.Parameters.Add("@KID", SqlDbType.Int).Value = strKID
        cmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = strLastName
        cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = strFirstName

        conn.Open()

        cmd.ExecuteNonQuery()
    End Using

    gvCustmor.EditIndex = -1
    bind()
    lbtnAdd.Visible = True
End Sub

Protected Sub gvCustmor_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
    Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("SQLServer2005DBConnectionString").ToString())
        ' Create a command object.
        Dim cmd As New SqlCommand()

        ' Assign the connection to the command.
        cmd.Connection = conn

        cmd.CommandText = "DELETE FROM Kdata WHERE KID = @KID"

        cmd.CommandType = CommandType.Text

        Dim strKID As String = gvCustmor.Rows(e.RowIndex).Cells(2).Text

        cmd.Parameters.Add("@KID", SqlDbType.Int).Value = strKID

        ' Open the connection.
        conn.Open()

        ' Execute the command.
        cmd.ExecuteNonQuery()
    End Using
    gvCustmor.EditIndex = -1
    ' Rebind the GridView control to show data after deleting.
    bind()
End Sub

' GridView.Sorting Event
Protected Sub gvCustmor_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
    Dim strSortExpression As String() = ViewState("SortExpression").ToString().Split(" "c)

    ' If the sorting column is the same as the previous one,
    ' then change the sort order.
    If strSortExpression(0) = e.SortExpression Then
        If strSortExpression(1) = "ASC" Then
            ViewState("SortExpression") = Convert.ToString(e.SortExpression) & " " & "DESC"
        Else
            ViewState("SortExpression") = Convert.ToString(e.SortExpression) & " " & "ASC"
        End If
    Else
        ' If sorting column is another column,
        ' then specify the sort order to "Ascending".
        ViewState("SortExpression") = Convert.ToString(e.SortExpression) & " " & "ASC"
    End If

    ' Rebind the GridView control to show sorted data.
    bind()
End Sub
    End Class

解决方案

问题找到了:

GridView的EnableViewState属性设置为false,GridView的一些事件就不会执行,比如romcommand事件 rowupdating事件等
本文来自:读书人网(http://www.reader8.cn/)原文链接:http://www.reader8.cn/jiaocheng/20120316/1615649.html

解决方案二:

http://bbs.csdn.net/topics/350202683

时间: 2024-07-28 16:51:38

contentplaceholder-gridview 放在ContentPlaceHolder下,不能更新的相关文章

struts-Struts2的web.xml为什么要放在WEB-INF下

问题描述 Struts2的web.xml为什么要放在WEB-INF下 web.xml放在WebContent下问什么不可以呢,求指教 解决方案 webxml是tomcat装载页面的时候才用的,不是自身启动的必要.webinf是针对具体的war应用而设计的一个webinf对应一个具体的应用,tomcat 在加载这个war应用的时候根据webinf来具体解析网站结构.并启动浏览器来正确显示. 解决方案二: 因为你要启动tomcat,tomcat的启动项目文件你可以取tomcat里取查,至于Strut

[EGORefreshTableHeaderView]手动启动下拉更新的方法

Q:在EGORefreshTable中手动启动下拉更新的方法? A:EGORefreshTable中提供了方法,让用户下拉table到一定位置实现下拉更新的效果,现在我想复用这种效果用于table更新,比如我做一个按钮,当用户点击这个按钮时,执行这种数据加载中的效果,或者app刚刚启动时,也可以执行这个操作.详细参考代码 -(void) ViewFrashData{ [tblView setContentOffset:CGPointMake(0, -75) animated:YES]; [sel

webview可以调本地的h5 也可以调百度 为啥就是不能调自己写放在iis下的h5

问题描述 webview可以调本地的h5 也可以调百度 为啥就是不能调自己写放在iis下的h5 之前我记得是可以的 不知道改什么了 现在就是不行 求大佛指点啊 解决方案 404还是什么..iis机子开了防火墙还是杀毒?80端口通么? 解决方案二: 是访问不到iss你的html5网页??

仿新浪微博的ListView下拉更新功能

http://blog.csdn.net/wangkuifeng0118/article/details/7463594            OK,今天我们要实现的就是上面的下拉刷新功能.       首先实现下拉刷新的布局文件 layout/head.xml [html] view plaincopy <?xml version="1.0" encoding="utf-8"?>      <!-- ListView的头部 -->     

link环境下如何将结果按照条件分类放在treeviw下,谢谢!

问题描述 link环境下如何将结果按照条件分类放在treeviw下,谢谢! link环境下如何将结果按照条件分类放在treeviw下,谢谢!

jsp java-JSP和Java的Action结合下载文件以后返回jsp页面,能把页面上文件的下载量更新一下吗?

问题描述 JSP和Java的Action结合下载文件以后返回jsp页面,能把页面上文件的下载量更新一下吗? 这边是一个下载按钮,直接下载服务器上的一个pdf格式的文件,下载以后数据库里面的下载量会增加.但是页面上显示的下载量没有增加,有没有办法让后台在文件下载完成以后给前台返回一个信息,然后前台根据信息去刷新页面? 注释:用异步请求肯定是不行的,因为用Ajax异步请求的话,文件不能下载! 求高手指点!不好意思!刚注册的用户还没有搞明白我们这边的C币是怎么来的!希望高手不要介意! 解决方案 下载完

WP8.1下一个更新版本或7、8月间推出

WP8.1下一个更新版本或7.8月间推出诺基亚已开始正式推送基于WP8.1的"湖蓝"升级,而更令人期待的是,WP8.1的下一个更新也要来了.国外测试网站WPBench泄露信息显示,Windows Phone又一个全新的系统版本已经在测试中.该系统的版本号为8.10.14130.0,比目前的 WP8.1预览版(版本号为8.10.12397.895)要高出一些,预计性能也会有不小提升.据预计,这个最新泄露的系统更新很可能是Windows Phone 8.1 GDR1,后者将会在7.8月间推

诺基亚FAQ证实下一更新将为Lumia 710和800带来网络更新功能

在诺基亚发布的针对Lumia 900手机的FAQ,http://www.aliyun.com/zixun/aggregation/17253.html">常见问题解答页面中,我们发现诺基亚确定将很快为Lumia 610和Lumia 900带来网络共享功能.同时,在关于Lumia 710和Lumia 800的下一个更新中,也将增加网络共享功能的支持.原文如下: 问:Lumia系列手机上的网络共享功能什么时候推出? 答:很快用户即可通过zene来更新Lumia 800和Lumia 710手机,

如何获取GridView编辑状态下单元格里的值?

还在使用这样的代码吗? var txtName = grid1.Rows[e.RowIndex].Cells[0].FindControl("txtName") as TextBox;if (txtName != null){ // 读取值 //} 其实这些工作(在单元格中查找控件,并尝试获取其中的值)已经被封装了 .现在,只要调用 ExtractValuesFromCell 方法即可. 而该方法也被很多种列类型所支持: DataControlField, BoundField, Au