请问,想实现点击一个按钮,能实现本页面的内容改变,该怎么做?比如 首页的新闻是国际新闻,点按钮后,首页显示的是国内新闻。
解决方案 »
- URL中有#号如何来获取参数啊? 求教
- 带变量的窗口
- 在atlas框架使用文件上传功能为何不好使
- 想做一个网站计数器有一个难点问题?
- DataGrid中如何删除其中的行,只是显示没有了,而不更新数据库呢?
- 如何制作固定表头的DataGrid,不要滚动DataGrid的,不要用样式表控制的.
- TextBox设置为多行的时候,怎样保留原来的空格和回车格式?
- 如何获取一个UserControl的内容到一个string变量?(在线等)
- 最近我快晕了,都是treeview偌的祸,请教
- 兄弟姐妹们帮忙,学习ASP.NET一般用哪本教材比较好啊?!
- ASP.NET新手安装出现问题,请高手指教一下(急~~!!!)
- 在DataGrid模板列中加入了CheckBox控件,我如何获取勾选CheckBox时获得DataGrid的索引Indez
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
}
}
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>
/// MyMenuBar 的摘要说明。
/// </summary>
public class MyMenuBar : System.Web.UI.UserControl
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} public int EmpID
{
set
{
if(value > 0)
{
CreateMenus(value);
}
}
} private void CreateMenus(int id)
{
SqlConnection cn = new SqlConnection("server=.;database=northwind;uid=sa;pwd=;");
SqlDataAdapter da = new SqlDataAdapter("select shipname from orders where employeeid=" + id,cn);
DataTable dt = new DataTable();
da.Fill(dt); for(int i=0;i<dt.Rows.Count;i++)
{
HyperLink hl = new HyperLink();
hl.Text = dt.Rows[i][0].ToString();
hl.NavigateUrl = "";
this.Controls.Add(hl); Literal li = new Literal();
li.Text = "<br>";
this.Controls.Add(li);
} } #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
}
}