标题:通过ajax刷新页面后 gridview中的按钮都失效了,若通过超链接直接跳转就没有 ...
取消只看楼主
风铃082
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-12-29
结帖率:0
已结贴  问题点数:20 回复次数:2 
通过ajax刷新页面后 gridview中的按钮都失效了,若通过超链接直接跳转就没有问题
ajax的代码
程序代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1.aspx.cs" Inherits="_1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.">

<html xmlns="http://www.">
<head runat="server">
    <title></title>
        <script type="text/javascript">
            function loadXMLDoc(i) {

                var url = i;
                var xmlhttp;
                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
                    }
                }
                xmlhttp.open("POST", url, true);
                xmlhttp.send();
            }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
   
    <a href="#" onclick="loadXMLDoc('5.aspx')">超链接</a>
      <div id="myDiv" 

        style=" width:600px;margin:0 auto; text-align:center; font-size:12px; position:absolute; z-index:1; top: 303px; left: 421px;"></div>
    </form>
</body>
</html>



连接后的前台代码:
程序代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="5.aspx.cs" Inherits="_5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.">

<html xmlns="http://www.">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                        ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
                        OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit">
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="用户ID" ReadOnly="True" />
                            <asp:BoundField DataField="FuncName" HeaderText="用户姓名" />
                            <asp:BoundField DataField="FuncDesc" HeaderText="性别" />
                            <asp:BoundField DataField="FuncUrl" HeaderText="家庭住址" />
                            <asp:CommandField HeaderText="选择" ShowSelectButton="True" />
                            <asp:CommandField HeaderText="编辑" ShowEditButton="True" />
                            <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
                        </Columns>
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                    </asp:GridView>
    </div>
    </form>
</body>
</html>



链接后的后台代码:
程序代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _5 : System.Web.UI.Page
{

    //清清月儿http://blog. 
    SqlConnection sqlcon;
    SqlCommand sqlcom;
    string strCon = "Data Source=(local);Database=GHRQ;Uid=sa;Pwd=sa";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }

    //删除
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string sqlstr = "delete from tree where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        sqlcon = new SqlConnection(strCon);
        sqlcom = new SqlCommand(sqlstr, sqlcon);
        sqlcon.Open();
        sqlcom.ExecuteNonQuery();
        sqlcon.Close();
        bind();
    }

    //更新
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        sqlcon = new SqlConnection(strCon);
        string sqlstr = "update tree set funcname='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',funcdesc='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',funcurl='"
            + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where id='"
            + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        sqlcom = new SqlCommand(sqlstr, sqlcon);
        sqlcon.Open();
        sqlcom.ExecuteNonQuery();
        sqlcon.Close();
        GridView1.EditIndex = -1;
        bind();
    }

    //取消
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }

    //绑定
    public void bind()
    {
        string sqlstr = "select * from tree";
        sqlcon = new SqlConnection(strCon);
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet myds = new DataSet();
        sqlcon.Open();
        myda.Fill(myds, "tree");
        GridView1.DataSource = myds;
        GridView1.DataKeyNames = new string[] { "ID" };//主键
        GridView1.DataBind();
        sqlcon.Close();
    }
}
搜索更多相关主题的帖子: PUBLIC 超链接 color ajax 
2015-12-29 18:39
风铃082
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-12-29
得分:0 
以下是引用aspic在2015-12-30 14:19:48的发言:

因为load过来的就是纯的html了,无法使用服务器事件



那有什么办法可以解决吗??
2016-01-02 15:25
风铃082
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-12-29
得分:0 
以下是引用aspic在2015-12-30 14:19:48的发言:

因为load过来的就是纯的html了,无法使用服务器事件



其实是想实现左边菜单,右边显示的,但是左边菜单的超链接通过ajax后,右边gridview的chick事件就都不行了
2016-01-02 16:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-460662-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028356 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved