我贴出认为重要的部分,请各位帮帮忙我的目的 CybManage.aspx里的GV 中的 imagebutton 绑上个JavaScript(传Type 和Id),点击后打开CybArticle.aspx?Type=edit&Id= 。
遇到的问题是: 我点击GV 里的imagebutton后 不能打开网页,有错误提示81行错
这是81行的内容:
                                                <input type="image" name="GridView1$ctl02$lkbEdit" id="GridView1_ctl02_lkbEdit" title="编辑" class="imageHand" src="images/edit.gif" onclick="javascript:openWindow('CybArticle.aspx?Type=edit&amp;Id=11');" style="border-width:0px;" />CybManage.aspx
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {            ImageButton lkbEdit = e.Row.FindControl("lkbEdit") as ImageButton;
            lkbEdit.Attributes.Add("onclick", "javascript:openWindow('CybArticle.aspx?Type=edit&Id=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "');");            HyperLink hlTitle = e.Row.FindControl("hlTitle") as HyperLink;
            hlTitle.Attributes.Add("onclick", "javascript:openWindow('CybArticle.aspx?Type=view&Id=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "');");        }
    }
CybArticle.aspx    public void initpage()
    {
        string type = Request.QueryString["Type"].ToString();        if (type == "view")
        {
            if (Request.QueryString["Id"] != null)
            {
                this.pnlview.Visible = true;
                string ID = Request.QueryString["Id"].ToString();
                initview(ID);
            }
        }
        else if (type == "edit")
        {
            if(Request.QueryString["Id"]!=null )
            {            this.pnleidt.Visible = true;
            string ID = Request.QueryString["Id"].ToString();
            initedit(ID);
            }
        }
        else if (type == "new")
        {
            this.pnleidt.Visible = true;
            //string ID = Request.QueryString["Id"].ToString();
            //initedit(ID);
        }
    }

解决方案 »

  1.   


    onclick="window.open('CybArticle.aspx?Type=edit&amp;Id=11');"
    参考
      

  2.   

    javascript:openWindow('CybArticle.aspx?Type=edit&amp;Id=11')openWindow这样能传值吗?
    你后台有代码传值了 
    把这个删了吧
      

  3.   

    我的那81行是 在调试的时候 看的IE 里的信息。 不是 前台 代码。 
    我下面贴出来的都是后台代码。  CybManage.aspx  传Type 跟Id  到CybArticle.aspx  。
    CybArticle.aspx 里不是有Request.QueryString["Type"].ToString();  
    LS 2位 看清楚了。
    还有1楼说的那个 错是不存在的。  那个符号转义后就是 & 了
      

  4.   

    你自己定义了个openWindow的函数?你的意思是不是window.open('CybArticle.aspx?Type=edit&Id=11')?
      

  5.   

    你自己定义了个openWindow的函数?你的意思是不是window.open('CybArticle.aspx?Type=edit&Id=11')?
      

  6.   

    window.open()不是openWindow
    openWindow你自定义函数?哪了?
      

  7.   

    我把全部的贴出来吧  - -|<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CybManage.aspx.cs" Inherits="CybManage" %><!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:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                &nbsp;</div>
            <asp:Panel ID="Panel1" runat="server" Height="0px" HorizontalAlign="Center" Width="90%">
                
                        <asp:HyperLink ID="Button1" runat="server" OnClick="Button1_Click" Text="新增" Height="27px" Width="79px" Target="_blank" />
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>&nbsp;<br />
                        <br />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </asp:Panel>
            <br />
            <asp:Panel ID="Panel2" runat="server" Height="0px" HorizontalAlign="Center" Width="90%">
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                            DataKeyNames="ID" PageSize="50"  Width="100%" 
                            OnRowCommand="GridView1_RowCommand" GridLines="None" DataSourceID="SqlDataSource1" 
                            OnRowDataBound="GridView1_RowDataBound"  >
                            <RowStyle BackColor="#E3EAEB" />
                            <AlternatingRowStyle BackColor="White" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <table cellspacing="0" cellpadding="0" width="100%" border="0">
                                            <tr>
                                                <td class="time" width="3%" height="22">
                                                    <img height="16" src="images/arromhome.gif" width="14"></td>
                                                <td class="time" width="15%">
                                                    <asp:Label runat="server" ID="lblDate" Text='<%# Eval("pd") %>'></asp:Label></td>
                                                <td width="70%" height="9">
                                                    <span style="cursor: hand">
                                                        <asp:HyperLink ID="hlTitle" NavigateUrl="" Target="_blank" runat="server" Text='<%# Eval("Title") %>'></asp:HyperLink></span>
                                                </td>
                                                <td width="15%" height="9">
                                                    <asp:ImageButton ID="lkbEdit" CommandArgument='<%# Eval("ID") %>' CssClass="imageHand"  
                                                        runat="server" ImageUrl="images/edit.gif" ToolTip="编辑"    />
                                                    <asp:ImageButton ID="lkbDelete" OnClientClick="javascript:return confirm('确定要删除文章么')"
                                                        CommandName="DelArticle" CssClass="imageHand" CommandArgument='<%# Eval("ID") %>'
                                                        runat="server" ToolTip="删除" ImageUrl="images/delete.gif" />
                                                </td>
                                            </tr>
                                        </table>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Left" />
                                </asp:TemplateField>
                            </Columns>
                            <EmptyDataTemplate>
                                没有搜索到文章
                            </EmptyDataTemplate>
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DBGoldLarkConnectionString4 %>"
                            SelectCommand="SELECT ID, Title, convert(char(10), Pdate,120) as pd FROM CYB ORDER BY ID DESC, Pdate DESC">
                        </asp:SqlDataSource>
                    </ContentTemplate>            </asp:UpdatePanel>
            </asp:Panel>
        </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;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;public partial class CybManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Button1.Attributes.Add("onclick", "javascripts:openWindow('CybArticle.aspx?Type=new&Id=" + " " + "')");
                Button1.NavigateUrl = "CybArticle.aspx?Type=new";        }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DelArticle")
            {
                try
                {
                    string sql = "delete  from CYB where ID=" + int.Parse(e.CommandArgument.ToString());
                    Label1.Text = sql;
                    DbClass f = new DbClass();
                    f.execSqlNO(sql);
                    Response.Redirect(Request.Url.ToString());
                }
                catch { }
            }    }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {            ImageButton lkbEdit = e.Row.FindControl("lkbEdit") as ImageButton;
                lkbEdit.Attributes.Add("onclick", "javascript:openWindow('CybArticle.aspx?Type=edit&Id=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "');");            HyperLink hlTitle = e.Row.FindControl("hlTitle") as HyperLink;
                hlTitle.Attributes.Add("onclick", "javascript:openWindow('CybArticle.aspx?Type=view&Id=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "');");        }
        }
    }
      

  8.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CybArticle.aspx.cs" Inherits="CybArticle" %>
    <%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %><!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:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            &nbsp;<br />
            <div style="width: 100%; text-align:left;">
                <asp:DropDownList ID="DropDownList1" runat="server" Width="166px">
                    <asp:ListItem Value="1">创业板1</asp:ListItem>
                    <asp:ListItem Value="2">创业板2</asp:ListItem>
                    <asp:ListItem Value="3">创业板3</asp:ListItem>
                    <asp:ListItem Value="4">创业板4</asp:ListItem>
                    <asp:ListItem Value="5">创业板5</asp:ListItem>
                    <asp:ListItem Value="6">创业板6</asp:ListItem>
                </asp:DropDownList></div>
        </div>
            <asp:Panel ID="pnlview" runat="server" Height="50px" HorizontalAlign="Center" Width="100%" Visible ="false"  >
                标题:<asp:TextBox ID="TextBox4" runat="server" Width="451px"></asp:TextBox><br />
                发布时间:<asp:TextBox ID="TextBox3" runat="server" Width="185px"></asp:TextBox>
                <hr />
                <asp:Literal ID="Literal1" runat="server"></asp:Literal><br />
                <br />
                <div style="width: 100%; text-align:center;">
                    <asp:Button ID="Button3" runat="server" Text="编辑" OnClick="Button3_Click" /></div>
            </asp:Panel>
            <asp:Panel ID="pnleidt" runat="server" Height="50px" HorizontalAlign="Center" Width="100%" Visible ="false"  >
                标题:<asp:TextBox ID="TextBox1" runat="server" Width="451px"></asp:TextBox><br />
                发布时间:<asp:TextBox ID="TextBox2" runat="server" Width="185px"></asp:TextBox>
                <hr />
                <asp:Panel ID="Panel1" runat="server" Width="90%" Height="400px">
                    <FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" BasePath="~/fckeditor/" Height="400px">
                    </FCKeditorV2:FCKeditor>
                    &nbsp;</asp:Panel>
                &nbsp;
                <asp:Button ID="Button2" runat="server" Text="保存" OnClick="Button2_Click" />
                &nbsp;&nbsp; &nbsp;<asp:Button ID="Button1" runat="server" Text="关闭" /></asp:Panel>
        </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;
    using System.Web.UI.HtmlControls;public partial class CybArticle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
            initpage();
            }        
        }    //初始化页面
        public void initpage()
        {
            string type = Request.QueryString["Type"].ToString();        if (type == "view")
            {
                if (Request.QueryString["Id"] != null)
                {
                    this.pnlview.Visible = true;
                    string ID = Request.QueryString["Id"].ToString();
                    initview(ID);
                }
            }
            else if (type == "edit")
            {
                if(Request.QueryString["Id"]!=null )
                {            this.pnleidt.Visible = true;
                string ID = Request.QueryString["Id"].ToString();
                initedit(ID);
                }
            }
            else if (type == "new")
            {
                this.pnleidt.Visible = true;
                System.DateTime currentTime = new System.DateTime(); 
                this.TextBox2.Text = currentTime.ToString("D"); 
                //string ID = Request.QueryString["Id"].ToString();
                //initedit(ID);
            }
        }
        public void initview(string id)
        {
            string sql = "select * from CYB where ID=" + int.Parse(id);
            DbClass f = new DbClass();
            DataSet ds = new DataSet();
            ds = f.execSql(sql);        if (ds.Tables.Count != 0)
            {
                this.TextBox4.Text = ds.Tables[0].Rows[0]["Title"].ToString();
                this.TextBox3.Text = ds.Tables[0].Rows[0]["Pdate"].ToString();
                this.Literal1.Text = ds.Tables[0].Rows[0]["Content"].ToString();
                this.DropDownList1.SelectedValue = ds.Tables[0].Rows[0]["Type"].ToString();
            }    }    public void initedit(string id)
        {
            if (id == "")//新增insert into
            {        }
            else//编辑 更新update操作
            {
                //载入先
                string sql = "select * from CYB where ID=" + int.Parse(id);
                DbClass f = new DbClass();
                DataSet ds = new DataSet();
                ds = f.execSql(sql);            if (ds.Tables.Count != 0)
                {
                    this.TextBox1.Text = ds.Tables[0].Rows[0]["Title"].ToString();
                    this.TextBox2.Text = ds.Tables[0].Rows[0]["Pdate"].ToString();
                    this.FCKeditor1.Value = ds.Tables[0].Rows[0]["Content"].ToString();
                    this.DropDownList1.SelectedValue = ds.Tables[0].Rows[0]["Type"].ToString();
                }
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            string type = Request.QueryString["Type"].ToString();
            if (type == "edit")
            {
                string sql = "update CYB set Title=";
                sql += this.TextBox1.Text.ToString() + ",Pdate =";
                sql += this.TextBox2.Text.ToString() + ",Type=";
                sql += this.DropDownList1.SelectedValue.ToString() + ",Content=";
                sql += this.FCKeditor1.Value + "where ID=" + Request.QueryString["Id"].ToString();
                DbClass f = new DbClass();
                f.execSqlNO(sql);
            }
            else if (type == "new")
            {
                string sql = "INSERT INTO CYB (Title,Pdate,Content,Type) values('";
                sql += this.TextBox1.Text.ToString() + "',getdate()";
                sql +=   ",'";
                sql += this.FCKeditor1.Value + "','";
                sql += this.DropDownList1.SelectedValue.ToString() + "')";            DbClass f = new DbClass();
                f.execSqlNO(sql);
                Response.Write("<script>window.opener=null;window.close();</script>");// 不会弹出询问
            }
        }    protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("CybAtricle.aspx?" + Request.QueryString.ToString().Replace("view", "edit"));
        }
    }
      

  9.   

    &amp;  
    &就好了!
      

  10.   

    找到问题,忘了引用JAVASCRIPT 
    // JScript File
    function openWindow(surl)
    {
    var newwin = window.open('','_blank','scrollbars=1,resizable=1,left=0,top=0,width=620,height=420');
    newwin.location=surl;
    newwin.focus();
    }