Response对象的write方法

除了最简单的用response.write方法向浏览器端输出信息,

1.用HTML语法方式向浏览器发送字符串。使用write方法输出的字符串被浏览器按HTML语法进行解释,因此可以用write方法直接输出HTML代码,实现网页元素及格式的定制,在以下页面以表格布局方式显示查询数据库的记录。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="WebApplication2.WebForm6" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%--<asp:Table ID="Table1" GridLines="horizontal" runat="server">
        <asp:TableRow><asp:TableCell>xuehao</asp:TableCell><asp:TableCell>name</asp:TableCell></asp:TableRow>
     </asp:Table>--%>
        <table style="width: 100%; font-size: medium; color: #FF0000;" bgcolor="Lime" 
            border="2px">
            <tr>
                <td>学号 </td><td>姓名</td>
            </tr>
            <%
                OleDbConnection conn = new
             OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Database1.accdb");
                conn.Open();
                OleDbCommand cd = new OleDbCommand("select * from userinf where UClass='数媒一班' ", conn);
                OleDbDataReader dr = cd.ExecuteReader();
                while (dr.Read())
                {
                    Response.Write("<tr><td>" + dr["UID"] + "</td><td>" + dr["UName"] + "</td></tr>");
                }
                dr.Close();
                conn.Close(); 
                 %>
        </table>
    </div>
    </form>
</body>
</html>


本来我是想用ASP.NET的控件table显示的,但是最后发现会有错误,没有实现用HTML表格的那种效果。 PS:求高手指点


2.response对象的redirect方法

在网页中单击一个超链接源,可以将访问者引导到指定的页面上,并可根据不同的条件将访问者重定向到不同的页面,常用于登陆页面。

<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />

 protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("WebForm6.aspx");
        }

就可以重定向了。

3.end方法,功能是结束程序的执行,若缓冲区有数据,则会将其输入到客户端,

 Response.Write("shuju");
            Response.End();
            Response.Write("kaishi");

这样写的话,后面的kaishi就不会显示出来,end()方法停止了该方法的运行。




你可能感兴趣的:(html,C#,table,asp.net,控件)