日期:2014-05-17 浏览次数:20360 次
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> ...... <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center" runat="server"> <tr> <td height="23" class="ye" valign="top" align="left"> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </td> <td background="images/bg_center.jpg" width="1"></td> <td> <asp:Label ID="Label2" runat="server" Text=""></asp:Label> </td> </tr> </table> ......
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ...... displayteacher(); } } ...... private void displayteacher() { DataClass dc = new DataClass(); SqlConnection conn = DataClass.GetSqlServerConn(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select top 10 teacher_name,teacher_id from teacher order by teacher_date desc"; try { cmd.Connection = conn; SqlDataReader dr = cmd.ExecuteReader(); int i = 0; while (dr.Read()) { string str1 = dr.GetString(0); str1 = StrCut(str1, 25); i = i + 1; if (i > 0 && i <= 5) { Label1.Text = Label1.Text + "<p/> " + "⊙ " + "<a href='teacher_content.aspx?teacher_id=" + dr[1] + "'>" + str1 + "</a>"; } else if (i > 5 && i <= 10) { Label2.Text = Label2.Text + "<p/> " + "⊙ " + "<a href='teacher_content.aspx?teacher_id=" + dr[1] + "'>" + str1 + "</a>"; } //Response.Write("/n"); } } catch (SqlException sex) { throw sex; } finally { DataClass.CloseSqlServerConn(conn); } } }