public string FormatWebFormTextBox(System.Web.UI.Page pg,string FormatValue)
{
string ResultString = "";
foreach (System.Web.UI.Control Con in pg.Controls)
{
ResultString = Con.ToString();
}
return ResultString;
}

解决方案 »

  1.   

    storm97(风暴不再) 
    不好意思,你说的得到的结果是下面的,是不正确的!不好意思!"System.Web.UI.LiteralControl"
      

  2.   

    public string FormatWebFormTextBox(System.Web.UI.Page pg)
    {
    string ResultString = "";
    foreach (System.Web.UI.Control Con in pg.Controls)
    {
    //if(Con.)
    ResultString = Con.ToString();
    if(ResultString=="System.Web.UI.HtmlControls.HtmlForm")
    {
    foreach (System.Web.UI.Control  txt in Con.Controls)
    {
    //txt.Text="your value";
    Response.Write(txt.ToString());
    }
    }
    Response.Write(ResultString+"<br>");
    }
    return ResultString;
    }
      

  3.   

    billqi(bill) 谢谢你的帮助,遗憾的是偶想的要得结果并不是这样。简单的说就是通过传递一个"this",遍历整个"this",看看里面是不是有TextBox控件、或者ListBox控件、或者是其他控件,完后对"this"中的不同控件,根据它们不同的属性格式化他们,以便被调用时显示的格式化后的结果!
      

  4.   

    wincore(七点)public string FormatWebFormTextBox(System.Web.UI.Control obj,string FormatValue)
    {
          遍历ojbj参数内的控件,如果是一个TextBox的话,TextBox.Text = FormatValue
    }这时显示在WEB页上面的TextBox显示FormatValue的值!
      

  5.   

    tqz2003(谈谈)说的太对了,要不偶也就不用问了!
      

  6.   

    zhangrui135(C#.NET教父)不好意思!你说的是什么意思!???可以说明白些吗!?
      

  7.   

    to NicholasZhr(存储过程) 
    我明白你的意思,如果用想遍历页面中包含的所有控件,为了方便,应该是把这些控件放在一个runat server的form中,也就是一个HtmlForm中,看如下代码是否满足你的要求?
    另(你是想写一个通过的页面存取类吧?)
    /// <summary>
    /// 查找page中所有在form中的控件,并格式化其值
    /// 如:FormatWebFormTextBox(this.page)
    /// </summary>
    /// <param name="pg">page对象</param>
    public void FormatWebFormTextBox(System.Web.UI.Page pg)
    {
    string ResultString = "";
    foreach (System.Web.UI.Control Con in pg.Controls)
    {
    //判断是否form控件
    if(Con.GetType()==System.Type.GetType("System.Web.UI.HtmlControls.HtmlForm"))
    {
    //遍历form内的所有控件,并格式化其值
    foreach (System.Web.UI.Control  formCon in Con.Controls)
    {
    //Response.Write(formCon.ToString());
    System.Type sType=formCon.GetType();
    switch(sType.ToString())
    {
    case "System.Web.UI.WebControls.TextBox":
    ((System.Web.UI.WebControls.TextBox)formCon).Text="your format value";
     break;
    case "System.Web.UI.WebControls.ListBox":
    ((System.Web.UI.WebControls.ListBox)formCon).SelectedItem.Value="your format value";
    break;
    case "System.Web.UI.WebControls.HyperLink":
    ((System.Web.UI.WebControls.HyperLink)formCon).Text="your format value";
    ((System.Web.UI.WebControls.HyperLink)formCon).NavigateUrl="www.china.com";
    break;
    case "System.Web.UI.HtmlControls.HtmlInputCheckBox":
    ((System.Web.UI.HtmlControls.HtmlInputCheckBox)formCon).Checked=true;
    break;
    default :
    ((System.Web.UI.WebControls.TextBox)formCon).Text="your format value";
    break;
    } //end switch


    } //end for
    } //end if 

    } //end for
    } //end method
      

  8.   

    billqi(bill)
    说的对,还是你聪明呀,终于明白偶的意思了!