日期:2014-05-20  浏览次数:20465 次

首页内容怎么实现全部更换?
请问,想实现点击一个按钮,能实现本页面的内容改变,该怎么做?

比如   首页的新闻是国际新闻,点按钮后,首页显示的是国内新闻。

------解决方案--------------------
改变绑定的数据可以满足,即改变数据源
------解决方案--------------------
看看这个自定义控件的代码,有帮助!!
namespace ch09.CommonControl
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// MyToolBar 的摘要说明。
/// </summary>
public class MyToolBar : System.Web.UI.UserControl
{
public delegate void delOnButtonClick(int id);
public event delOnButtonClick OnButtonClick;

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

private void CreateButtons()
{
SqlConnection cn = new SqlConnection( "server=.;database=northwind;uid=sa;pwd=; ");
SqlDataAdapter da = new SqlDataAdapter( "select * from employees ",cn);
DataTable dt = new DataTable();
da.Fill(dt);

for(int i=0;i <dt.Rows.Count;i++)
{
LinkButton lb = new LinkButton();
lb.Text = dt.Rows[i][ "firstname "].ToString()+ " | ";
lb.CommandName = dt.Rows[i][ "employeeid "].ToString();
lb.Click += new EventHandler(lb_Click);
this.Controls.Add(lb);
}
}

private void lb_Click(object sender,System.EventArgs e)
{
LinkButton lb = (LinkButton)sender;
OnButtonClick(int.Parse(lb.CommandName));
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}



------解决方案--------------------
还有些没给,自己看看吧,如要,说说
------解决方案--------------------
有点不清楚你想要什么,算是帮你顶了.