zoukankan      html  css  js  c++  java
  • Asp.net 动态生成页面中的内容

    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(@"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");

                
    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);
                }
            }
  • 相关阅读:
    在公司中使用springboot技术的经验
    使用swagger2代替api文档
    第一份正式工作-华为外包。
    zookeeper学习入门
    dubbo入门
    C/C++编程笔记:inline函数的总结!C/C++新手值得收藏!
    刚毕业入职程序员?程序员需注意这 6 点!都是前辈“血的教训”
    你在群里提的技术问题没人回答!是为什么?因为没注意这 4 点!
    程序人生:程序员想要提升英文阅读能力怎么办?实用秘籍推荐!
    程序员必看:长期工作的程序员转眼变油腻大叔!你今天护肤了吗?
  • 原文地址:https://www.cnblogs.com/scottckt/p/1494730.html
Copyright © 2011-2022 走看看