下面是绑到GridView模板上的,请如何去除HTML格式显示出来!
<%# DataBinder.Eval(Container.DataItem, "About") %>这个方法是写在类里面的,但是在模板不可以创建对象!
public string Filter(string str, string mode)
    {
        mode = mode.ToLower();
        switch (mode)
        {
            case "html":
                str = str.Replace("\r\n", "\n");
                str = str.Replace("'", "&#39;");
                str = str.Replace("\"", "&#34;");
                str = str.Replace("<", "&#60;");
                str = str.Replace(">", "&#62;");
                str = str.Replace("\n", "<br />");
                break;
            case "nohtml":
                str = Regex.Replace(str, "<[^>]*>", "");
                break;
            case "sql1":
                str = str.Replace("'", "");
                str = str.Replace(";", "");
                break;
            case "htmltojs":
                str = str.Replace("\r\n", "\n");
                str = str.Replace(@"\", @"\\");
                str = str.Replace("'", "\\\'");
                str = str.Replace("\"", "\\\"");
                str = str.Replace("/", "\\/");
                str = str.Replace("\n", "<br />");
                str = str.Replace(" ", "&nbsp;");
                break;
            default:
                str = str.Replace("'", "''");
                str = str.Replace(";", ";");
                break;
        }
        return str;
    }
这样不行啊,,,创业不了对象名 如果对象名为 SqlDAL word=new SqlDAL()
<%# word.Filter(DataBinder.Eval(Container.DataItem, "About"),"nohtml" %>
面里不支持....
GridView字段为什么不支持赋值?比如: string strabout=DataBinder.Eval(Container.DataItem, "About") 这像根本不支持,要命!!!!救命啊.....

解决方案 »

  1.   

    处理比较复杂的话,还是放到后端用FindControl()的方法赋值.
    例如:Label1是你放在模板列里面需要显示数据的控件.protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl = (Label)e.Row.Cells[0].FindControl("Label");//假设模板列是Grid的第一列
                lbl.Text = "你需要显示的数据";
            }
        }
      

  2.   

      protected SqlDAL   word=new   SqlDAL() 
    <%#   word.Filter(Eval("About").ToString(),"nohtml")   %> 
      

  3.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl = (Label)e.Row.Cells[0].FindControl("Label");//假设模板列是Grid的第一列
                lbl.Text = "你需要显示的数据";
            }
        }这种方法怎么读取字段内容??? lbl.Text = "你需要显示的数据";  字段名为:About 
      

  4.   

    在页面<%Page 里加一个属性   ValidateRequest="false"