我贴出认为重要的部分,请各位帮帮忙我的目的 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&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);
}
}
遇到的问题是: 我点击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&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);
}
}
解决方案 »
- 各位帮忙看看这个是怎么回事?
- 大家帮我改下,谢了!
- 求一条select
- MasterPage母版优先级的问题!
- 大家说说 一个用ASP.NET1.1作的大型网站,一个经过编译的DLL文件最大的有多大(ASPNET1.1只有一个DLL文件吧)
- 刚开始用vs2010新建asp.net网站,一直出现“欢迎试用asp.net”!怎么不让它出现
- ASP.NET 简单问题 小弟是在不解 望大家开导开导 感谢感谢啊!
- 100分求助,网站每天自动备份
- 建个“投诉信息”表,起个什么名字合规范?
- 重装了系统,原来可运行的程序不能用了!!!!!
- 读取聊天记录时的问题(需要重新启动程序)
- asp.net 在继承母版页的页面使用js日历控件
onclick="window.open('CybArticle.aspx?Type=edit&Id=11');"
参考
你后台有代码传值了
把这个删了吧
我下面贴出来的都是后台代码。 CybManage.aspx 传Type 跟Id 到CybArticle.aspx 。
CybArticle.aspx 里不是有Request.QueryString["Type"].ToString();
LS 2位 看清楚了。
还有1楼说的那个 错是不存在的。 那个符号转义后就是 & 了
openWindow你自定义函数?哪了?
<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>
</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> <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() + "');"); }
}
}
<%@ 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>
<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>
</asp:Panel>
<asp:Button ID="Button2" runat="server" Text="保存" OnClick="Button2_Click" />
<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"));
}
}
&就好了!
// 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();
}