0

我想要做的只是在 SQL 数据库中获取月份和日期的日期并将其绑定到转发器中:

正面:

<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("BLG_DATE") %> of <span><%#Eval("BLG_DATE") %></span>
</div>
</ItemTemplate>
</repeater>

背部:

daString = "SELECT * FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID WHERE [BLG].ACC_ID='" + userID + "'";
SqlDataAdapter da = new SqlDataAdapter(daString, conn);
DataTable dt = new DataTable();
da.Fill(dt);    
rep_content.DataSource = dt;
rep_content.DataBind();

BLG表:

BLG_ID,ACC_ID,BLG_TITLE,BLG_DES,BLG_DATE,BLG_IMG    

输出应该是:

23 of JAN
4

2 回答 2

1

用于DatePart获取日期和月份

 daString = "SELECT datepart (dd, BLG_DATE) as DDay,datepart (mm, BLG_DATE) as DMonth
  FROM [BLG] INNER JOIN [ACC] ON [BLG].ACC_ID=[ACC].ACC_ID 
    WHERE [BLG].ACC_ID='" + userID + "'";
 SqlDataAdapter da = new SqlDataAdapter(daString, conn);
 DataTable dt = new DataTable();
 da.Fill(dt);    
 rep_content.DataSource = dt;
 rep_content.DataBind();


 <p><%# Eval("DDay") %> of <span><%#Eval("DMonth") %></span>
于 2013-08-01T02:21:51.613 回答
0

这样做,

<asp:Repeater ID="rep_content" runat="server">
<ItemTemplate>
<div class="date">
<p><%# Eval("DDay") %> of <span><%#System.Globalization.DateTimeFormatInfo.InvariantInfo.GetAbbreviatedMonthName(Convert.ToInt32(Eval("DMonth")))%></span>
</div>
</ItemTemplate>
</repeater>
于 2013-08-01T02:50:44.607 回答