我正在创建一个社交网络网站作为Facebook,但该网站在姿势状态方面存在一些错误,我使用以下代码发布状态。我在事件和发布按钮上调用了此方法page_Load
private DataSet GetData()
{
string CS=ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlDataAdapter da = new SqlDataAdapter("Select * from PhotoStatusProfile WHERE Email = '" + Session["Email"].ToString() +"'",con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
这是 html 代码
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<div class="yourDivClass" style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px; height: 121px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #e9eaee; border-left-color: #BBCEB3; border-right-color: #BBCEB3;">
<br />
<div style="width: 58px; height: 62px">
<asp:Image ID="Image1" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/supun_Profilemini.jpg" Width="55px" />
</div>
<div style="width: 307px; height: 21px; margin-left: 65px; margin-top: -60px">
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066" ><%#Eval("name") %> </asp:Label>
</div>
<div style="height: 22px; width: 461px; margin-left: 78px; margin-top: 11px"> <asp:Label ID="Label8" runat="server"><%#Eval("Status") %></asp:Label>
<br><br>
</div>
</div>
</ItemTemplate>
"开机自检"按钮 CS 代码
protected void Post_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
try
{
string inserQuery = "insert into PhotoStatusProfile(Name,Status,Email) values (@Name,@Status,@e)";
SqlCommand commm = new SqlCommand(inserQuery, conn);
commm.Parameters.AddWithValue("@Name", ProfileName.Text);
commm.Parameters.AddWithValue("@Status",TextBox1.Text);
commm.Parameters.AddWithValue("@e", Label1.Text);
commm.ExecuteNonQuery();
Label1.Text = Session["Email"].ToString();
}
catch (Exception ex)
{
Response.Write("Error -->" + ex.ToString());
conn.Close();
}
// LoadData();
Repeater1.DataSource = GetData();
Repeater1.DataBind();
TextBox1.Text = "";
}
但是在我发布一些状态后,我遇到了一些错误。
1,在这个网站上,我的新帖子显示在底部,最旧的帖子显示在顶部,但我希望新帖子显示在顶部,其他帖子逐渐从上到下,(考虑时间降序(
- 当我发布大状态时,它会显示如下。我也想解决这个问题。谢谢
您应该考虑为每个帖子存储某种日期。然后,您可以从数据库中获取排序列表。像这样:
SqlDataAdapter da = new SqlDataAdapter("Select * from PhotoStatusProfile WHERE Email = '" + Session["Email"].ToString() +" order by CreatedAt desc'",con);
这也将允许您显示"发布"日期,按天/周/月显示帖子等。
反转中继器顺序
要进行长自动换行,您可以应用 css:
word-wrap: break-word;