protected void Page_Load(object sender, EventArgs e)
{
//声明强类型DataClasses1DataContext的对象dc
DataClasses1DataContext dc = new DataClasses1DataContext();
if (!IsPostBack)
{
//将留言中的数据信息列表作为GridView1控件的数据源
GridView1.DataSource = dc.GuestBookInfo.ToList();
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc=new DataClasses1DataContext();
string name = TextBox1.Text.Trim();//获得文本框输入的留言人
//使用LINQ查询出GuestBookInfo中该留言人的数据信息
var bookquery =
from b in dc.GuestBookInfo
where b.Name == name
select b;
GridView1.DataSource = bookquery;//将查询结果作为数据源
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
string name = TextBox2.Text.Trim();
string detail = TextBox3.Text.Trim();
//根据用户输入的留言人和留言内容创建留言信息对象
GuestBookInfo guest = new GuestBookInfo { Name = name, Detail = detail, Time = DateTime.Now.ToLongTimeString(), Back = "" };
dc.GuestBookInfo.InsertOnSubmit(guest);//提交添加的操作
dc.SubmitChanges();//更新数据库信息
GridView1.DataSource = dc.GuestBookInfo.ToList();
GridView1.DataBind();
}
protected void delete_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
string name = input.Text.Trim();
GuestBookInfo guest = dc.GuestBookInfo.First(p => p.Name.StartsWith(name));//获得要删除的留言信息对象
dc.GuestBookInfo.DeleteOnSubmit(guest);//提交删除
dc.SubmitChanges();//提交数据库更改信息
GridView1.DataSource = dc.GuestBookInfo.ToList();
GridView1.DataBind();
}
}
}
{
//声明强类型DataClasses1DataContext的对象dc
DataClasses1DataContext dc = new DataClasses1DataContext();
if (!IsPostBack)
{
//将留言中的数据信息列表作为GridView1控件的数据源
GridView1.DataSource = dc.GuestBookInfo.ToList();
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc=new DataClasses1DataContext();
string name = TextBox1.Text.Trim();//获得文本框输入的留言人
//使用LINQ查询出GuestBookInfo中该留言人的数据信息
var bookquery =
from b in dc.GuestBookInfo
where b.Name == name
select b;
GridView1.DataSource = bookquery;//将查询结果作为数据源
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
string name = TextBox2.Text.Trim();
string detail = TextBox3.Text.Trim();
//根据用户输入的留言人和留言内容创建留言信息对象
GuestBookInfo guest = new GuestBookInfo { Name = name, Detail = detail, Time = DateTime.Now.ToLongTimeString(), Back = "" };
dc.GuestBookInfo.InsertOnSubmit(guest);//提交添加的操作
dc.SubmitChanges();//更新数据库信息
GridView1.DataSource = dc.GuestBookInfo.ToList();
GridView1.DataBind();
}
protected void delete_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
string name = input.Text.Trim();
GuestBookInfo guest = dc.GuestBookInfo.First(p => p.Name.StartsWith(name));//获得要删除的留言信息对象
dc.GuestBookInfo.DeleteOnSubmit(guest);//提交删除
dc.SubmitChanges();//提交数据库更改信息
GridView1.DataSource = dc.GuestBookInfo.ToList();
GridView1.DataBind();
}
}
}