1、在页面中指定地方增加PlaceHolder
2、在PlaceHolder中增加控件。
注:生成控件的代码需放在Page_Load中 ,且不能加IsPostBack判断。否则找到不控件。
示例代码:
string sSQl = "";
sSQl = @"select sfcId,sfcDeptID,sfcTableName,sfcTabletitle
from hp_satisfactioncreate ssc";
sSQl = string.Format(sSQl, Resources.Resource.SysSatisfactionDept);
DataView dvData = TDAIClient.BusinessDB.GetDataView(sSQl);
if (dvData != null)
{
//增加回车
//LiteralControl lcVal = new LiteralControl("<br/>");
//增加空格
//LiteralControl lcSpace = new LiteralControl(@" ");
if (dvData.Count > 0)
{
/*
* 此处生成一个两列的表
*/
//定义表
HtmlTable htTab = new HtmlTable();
htTab.Style.Add(HtmlTextWriterStyle.Width, "100%");
//定义表中的行
HtmlTableRow htrTr = new HtmlTableRow();
for (int iRow = 0; iRow < dvData.Count; iRow++)
{
//定义行中的例
HtmlTableCell htcTd = new HtmlTableCell();
htcTd.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
htcTd.Style.Add(HtmlTextWriterStyle.Color, "blue");
//定义LinkButton控件
LinkButton lbn = new LinkButton();
lbn.Text = dvData[iRow]["sfcTabletitle"].ToString();
lbn.ToolTip = dvData[iRow]["sfcId"].ToString();
string sUrl = "SysSatisfactionDept.aspx?strID={0}";
sUrl = string.Format(sUrl, dvData[iRow]["sfcId"].ToString());
lbn.PostBackUrl = sUrl;
//增加控件
htcTd.Controls.Add(lbn);
htrTr.Cells.Add(htcTd);
htTab.Rows.Add(htrTr);
if (iRow % 2 == 0)
{
htrTr = new HtmlTableRow();
}
}
phControl.Controls.Add(htTab);
}
}
sSQl = @"select sfcId,sfcDeptID,sfcTableName,sfcTabletitle
from hp_satisfactioncreate ssc";
sSQl = string.Format(sSQl, Resources.Resource.SysSatisfactionDept);
DataView dvData = TDAIClient.BusinessDB.GetDataView(sSQl);
if (dvData != null)
{
//增加回车
//LiteralControl lcVal = new LiteralControl("<br/>");
//增加空格
//LiteralControl lcSpace = new LiteralControl(@" ");
if (dvData.Count > 0)
{
/*
* 此处生成一个两列的表
*/
//定义表
HtmlTable htTab = new HtmlTable();
htTab.Style.Add(HtmlTextWriterStyle.Width, "100%");
//定义表中的行
HtmlTableRow htrTr = new HtmlTableRow();
for (int iRow = 0; iRow < dvData.Count; iRow++)
{
//定义行中的例
HtmlTableCell htcTd = new HtmlTableCell();
htcTd.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
htcTd.Style.Add(HtmlTextWriterStyle.Color, "blue");
//定义LinkButton控件
LinkButton lbn = new LinkButton();
lbn.Text = dvData[iRow]["sfcTabletitle"].ToString();
lbn.ToolTip = dvData[iRow]["sfcId"].ToString();
string sUrl = "SysSatisfactionDept.aspx?strID={0}";
sUrl = string.Format(sUrl, dvData[iRow]["sfcId"].ToString());
lbn.PostBackUrl = sUrl;
//增加控件
htcTd.Controls.Add(lbn);
htrTr.Cells.Add(htcTd);
htTab.Rows.Add(htrTr);
if (iRow % 2 == 0)
{
htrTr = new HtmlTableRow();
}
}
phControl.Controls.Add(htTab);
}
}