用户控件

 // 用户控件源码

 namespace wzjr.control
{
public partial class Topic : System.Web.UI.UserControl
{ public int FatherTopic
{
get
{
return (int)ViewState["Topic"];
}
set
{
ViewState["Topic"] = value;
}
} public string FatherName
{
get
{
return ViewState["Name"].ToString();
}
set
{
ViewState["Name"] = value;
}
} public string Position
{
get
{
return ViewState["position"].ToString();
}
set
{
ViewState["position"] = value;
}
} protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.BLL_Topic bllTopic = new BLL.BLL_Topic(); DataTable dt = bllTopic.GetChild(FatherTopic); repZhishu.DataSource = dt; DataBind(); }
}
}
}

aspx页面

 // .cs文件源码

  wzjr.control.Topic topicControl = (wzjr.control.Topic)LoadControl("control/Topic.ascx");

   // 父栏目ID
topicControl.FatherTopic = Topic; // 父栏目名称
topicControl.FatherName = Name; // 当前位置
topicControl.Position = position; phControl.Controls.Add(topicControl);

转自:http://blog.csdn.net/handsometone1982/article/details/7874338

05-11 17:32