日期:2014-05-18 浏览次数:20423 次
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Linq; public partial class _Default : System.Web.UI.Page { GuestBookDataContext ctx = new GuestBookDataContext("server=.;database=JumbotOA;uid=sa;pwd=sa!#%246"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SetBind(); } } private void SetBind() { rpt_Message.DataSource = from c in ctx.tbGuestBook orderby c.PostTime ascending select new { c.UserName, c.PostTime, c.Message, c.IsReplied, c.Reply }; rpt_Message.DataBind(); } protected void btn_SendMessage_Click(object sender, EventArgs e) { tbGuestBook gb = new tbGuestBook(); gb.UserName = tb_UserName.Text; gb.Message = tb_Message.Text; gb.IsReplied = false; gb.PostTime = DateTime.Now; ctx.tbGuestBook.Add(gb); ctx.SubmitChanges(); SetBind(); } }