ASP.NET毕业设计的问题,哪位大侠能帮忙解决一下啊,谢谢了。
我要做一个页a.aspx,上面有四个链接,连接到一个页上,只是传的name值不同。a.aspx上有一个ifram,src=b.aspx,b页上有一个datagrid,如何点a页的连接把b页嵌入到a中,并接参数,根据参数查询。
--------------------编程问答-------------------- 什么参数? --------------------编程问答-------------------- 看不懂说什么,能否解释得详细一些? --------------------编程问答-------------------- 就是有四个图,每个图连到一个页,只是传的参数不同 --------------------编程问答-------------------- 例如:
<a href=b.aspx?name=时尚信息> --------------------编程问答-------------------- 超级连接传参是GET的提交方法通过 Request.QueryString["name"].ToString(); 来获取name的值 --------------------编程问答-------------------- 如何点连接的时候,将b页嵌入到a页中? --------------------编程问答-------------------- 刚开始的时候,iframe 可以连接到一个别的叶面,当click连接的时候再连到b.aspx --------------------编程问答-------------------- <a href=b.aspx?name=时尚信息 target='iframeName'>
加个target属性,值是你的iframe的名字就行了。OK 收分
--------------------编程问答-------------------- 我做了一个例子,你可以在我的例子上改。Form内部的代码:
<table style="border-width: 1px; border-style: solid" width="100%" cellpadding="10">
<tr>
<td valign="top">
<asp:PlaceHolder ID="Links" runat="server"></asp:PlaceHolder><br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="[S]随机选择一个置顶" AccessKey="S" />
</td>
<td valign="top">
请输入一个url:<br />
<asp:TextBox ID="TextBox1" runat="server" Width="344px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="[A]加入列表" AccessKey="A" />
</td>
</tr>
</table>
<asp:PlaceHolder ID="ShowPage" runat="server"></asp:PlaceHolder>
partial class类定义内的代码:
protected override void CreateChildControls()
{
base.CreateChildControls();
this.CreateSubControls();
}
bool SubControlsCreated = false;
private void CreateSubControls()
{
this.SubControlsCreated = true;
this.ShowPage.Controls.Clear();
this.Links.Controls.Clear();
HtmlGenericControl iframe = new HtmlGenericControl("iframe");
iframe.ID = "showInner";
this.ShowPage.Controls.Add(iframe);
iframe.Attributes["src"] = this.showPageUrl;
iframe.Style["width"] = "100%";
iframe.Style["height"] = "300px";
int k=0;
foreach (string url in UrlList)
{
LinkButton lnk = new LinkButton();
lnk.ID = "lnk_"+k.ToString();
k++;
this.Links.Controls.Add(lnk);
lnk.Click += new EventHandler(lnk_Click);
lnk.Text = url;
this.Links.Controls.Add(new LiteralControl("<br>"));
}
this.TextBox1.Text = "http://";
}
void lnk_Click(object sender, EventArgs e)
{
showPageUrl = ((LinkButton)sender).Text;
}
private string showPageUrl
{
get
{
if (ViewState["url"] == null) return string.Empty;
else return (string)ViewState["url"];
}
set
{
ViewState["url"] = value;
this.SubControlsCreated = false;
}
}
private List<string> UrlList
{
get
{
if (ViewState["us"] == null)
ViewState["us"] = new List<string>();
return (List<string>)ViewState["us"];
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.UrlList.Add(this.TextBox1.Text);
this.showPageUrl = this.TextBox1.Text;
this.SubControlsCreated = false;
}
protected override void OnPreRender(EventArgs e)
{
if (!this.SubControlsCreated)
CreateSubControls();
base.OnPreRender(e);
}
protected void Button2_Click(object sender, EventArgs e)
{
if (UrlList.Count == 0)
return;
int p = (new Random()).Next(1, UrlList.Count - 1);
string m = UrlList[p];
UrlList[p] = UrlList[0];
UrlList[0] = m;
this.showPageUrl = m;
this.SubControlsCreated = false;
}
如果编译时using有问题,我的这个是:
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.Collections.Generic;
--------------------编程问答-------------------- 我看了一下,上面有两行“this.SubControlsCreated = false;”是多余的,一行“CreateSubControls”的执行次序不对(提前一句)。 --------------------编程问答-------------------- --------------------编程问答-------------------- Click the link to solve your problem.Good luck!
补充:.NET技术 , ASP.NET