<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%#Eval("class").ToString().Replace(((char)10).ToString(), "<br/>") %>
</ItemTemplate>
</asp:Repeater>
<%#Eval("class").ToString().Replace(((char)10).ToString(), "<br/>") %>
将数据库中的数据原样输出
<%#Server.HtmlDecode(Eval("class").ToString().Replace(((char)10).ToString(), "<br/>")) %>
此时数据库中的HTML标识符数据会被解释为相应的效果
后台代码:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
string str = Server.HtmlEncode(TextBox1.Text);//编码后写入数据库,读出时可以包含html标识符
SqlCommand com = new SqlCommand("update stuInfo set class='"+str+"' where num='2001'", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
SqlCommand com = new SqlCommand("select class from stuInfo where num='2001'", con);
con.Open();
//Label1.Text = Server.HtmlDecode(com.ExecuteScalar().ToString());//取出数据库中的数据然后解码,读出数据将不包含html标识符,被转换为相应的效果
Label1.Text = com.ExecuteScalar().ToString(); //取出数据库中的数据不解码,数据库的数据原样输出
con.Close();