求救~!!!!!~~~对于"如何创建在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




}
}

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


...全文
143 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
具体的报错语句是什么?我看了一下感觉是你参数没有设好的事,可能是没有传过来
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2006-04-09 01:46
社区公告
暂无公告