asp.net简易留言板
源代码:
<asp:DataList ID="DataList1" runat="server" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
Height="16px" Width="848px">
<AlternatingItemStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<ItemTemplate>
<img src="p_w_picpath/1.jpg" height="40" width="40">
留言者: <%# Eval("username") %>
EMAIL: <%# Eval("email") %>
留言时间: <%# Eval("posttime")%> <asp:LinkButton
ID="LinkButton1" runat="server">回复留言</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server">删除留言</asp:LinkButton>
<br/><hr/>
留言内容: <%# Eval("contente")%> <br/><hr/>
回复内容: <%# Eval("reply")%> <br/><hr/>
</ItemTemplate>
</asp:DataList>
查看留言界面:
protected void Page_Load(object sender, EventArgs e)
{
string conn = "Data Source=.;Initial Catalog=Information;Integrated Security=True";
SqlConnection con = new SqlConnection(conn);
string sqlstr = "select*from Message";
SqlDataAdapter ad = new SqlDataAdapter(sqlstr,con);
DataSet ds = new DataSet();
con.Open();
ad.Fill(ds);
con.Close();
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataBind();
}
留言界面:
using System.Data.SqlClient;
using System.Data;
protected void Button2_Click(object sender, EventArgs e)//取消留言
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)//发送留言
{
string conn = "Data Source=.;Initial Catalog=Information;Integrated Security=True";
SqlConnection con = new SqlConnection(conn);
string sqlstr = "insert into Message(username,sex,email,contente,p_w_picpathadd)values('" + TextBox1.Text + "','" + RadioButtonList1.SelectedValue + "','" + TextBox2.Text + "','" + TextBox3.Text + "','3.jpg')";
SqlDataAdapter ad = new SqlDataAdapter(sqlstr, con);
DataSet ds = new DataSet();
ad.Fill(ds);
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。