求救~!!!!!~~~对于"如何创建在DataGrid 中使用HyperLinkColumn"出现点小问题,希望解决一下

X27794797 2006-04-09 01:46:22
按照网上的一个例子,自己试着做了一下下,出现点小问题,当我点"查看详细"的连接后,可以连接到WebForm2.aspx,并显示相对应详细数据,但是WebForm1.aspx里面就什么都没有了 页面出现[object],

是一点连接就会出现,是我什么地方写错了吗,
以下是代码WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="HowTos.DataGrid.PopupWindow.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 360px; POSITION: absolute; TOP: 136px"
runat="server" Width="424px" Height="208px" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ProductID" HeaderText="ProductID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="ProductName"></asp:BoundColumn>
<asp:HyperLinkColumn DataNavigateUrlField="ProductID" DataNavigateUrlFormatString="javascript:varwin=window.open('WebForm2.aspx?ProductID={0}',null,'width=692,height=500');"
DataTextField="ProductID" HeaderText="查看详细" DataTextFormatString="查看详细">
<HeaderStyle CssClass="HEADERSTYLE"></HeaderStyle>
<ItemStyle CssClass="ITEMSTYLEHYPERLINK"></ItemStyle>
</asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>

//WebForm1.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient ;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace HowTos.DataGrid.PopupWindow
{

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;

#region User Defined Code

private void Page_Load(object sender, System.EventArgs e)
{

if ( ! this.IsPostBack )
this.BindData();

}

protected void BindData()
{

SqlCommand cmd = new SqlCommand( "SELECT TOP 10 ProductID, ProductName FROM Products", con("Server=.; DataBase=Northwind;uid=sa;pwd="));
this.DataGrid1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
this.DataGrid1.DataBind();

}

protected SqlConnection con(System.String ConnectionString )
{

SqlConnection c = new SqlConnection( ConnectionString );
c.Open();
return c;

}

#endregion

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)
{

InitializeComponent();
base.OnInit(e);

}

private void InitializeComponent()
{
this.DataGrid1.PreRender += new System.EventHandler(this.Page_Load);
this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}
}
--------------------------------
//WebForm2.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient ;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace HowTos.DataGrid.PopupWindow
{

public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;

#region User Defined Code

private void Page_Load(object sender, System.EventArgs e)
{
if ( ! this.IsPostBack )
this.BindData();
}

protected void BindData()
{
SqlCommand cmd = new SqlCommand( "SELECT * FROM Products WHERE ProductID = @ProductID", con("Server=.; DataBase=Northwind; uid=sa;pwd="));
cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.VarChar, 200));
cmd.Parameters["@ProductID"].Value = Request["ProductID"].ToString();
this.DataGrid1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
this.DataGrid1.DataBind();
}

protected SqlConnection con(System.String ConnectionString )
{

SqlConnection c = new SqlConnection( ConnectionString );
c.Open();
return c;

}

#endregion

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)
{

InitializeComponent();
base.OnInit(e);

}

private void InitializeComponent()
{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion




}
}

代码基本是参照网上的,希望大虾给菜鸟解决一下,谢谢了


...全文
169 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
X27794797 2006-04-09
  • 打赏
  • 举报
回复
我想要的就是在DataGrid中创建一个弹出式窗口.看网上有例子,就访做了一下,结果就出现上面的问题了
bidisty 2006-04-09
  • 打赏
  • 举报
回复
<asp:HyperLinkColumn DataNavigateUrlField="ProductID" DataNavigateUrlFormatString="javascript:varwin=window.open('WebForm2.aspx?ProductID={0}',null,'width=692,height=500');"

为什么要用window.open?
javascript:去掉可以吗?试试
X27794797 2006-04-09
  • 打赏
  • 举报
回复
运行后我截的图http://bluekevin.go2.icpcn.com/work/1.jpg
点连接后的图http://bluekevin.go2.icpcn.com/work/2.jpg
关掉显示细节那个窗体后的图http://bluekevin.go2.icpcn.com/work/3.jpg
帮我看看 好吗 ?现谢谢了
X27794797 2006-04-09
  • 打赏
  • 举报
回复
没有报错,就是点了之后,出现[object],而不是出现现开始WebForm1.aspx所绑定的数据,我一会截个图吧
califord 2006-04-09
  • 打赏
  • 举报
回复
具体的报错语句是什么?我看了一下感觉是你参数没有设好的事,可能是没有传过来

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧