To format information of any format and in the case for Date (day, month and year) exists in this same method Eval
an overload where such an expected format can be made {0:dd/MM/yyyy}
as shown in the excerpt:
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="RptList" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "name") %>
<%# DataBinder.Eval(Container.DataItem, "created","{0:dd/MM/yyyy}") %>
<hr />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
where created
is a field in the type table date
. Reference: https://stackoverflow.com/questions/7621373/how-do-i-change-the-date-format-of-a-databinder-eval-in-asp-net/7621831
In the text Custom date and time format string has the table that explains the types of formats allowed for date or date and time:
+----------------------------------------------+--------------------------------------+
| "MM/dd/yyyy" | 07/21/2007 |
| "dddd, dd MMMM yyyy" | Saturday, 21 July 2007 |
| "dddd, dd MMMM yyyy HH:mm" | Saturday, 21 July 2007 14:58 |
| "dddd, dd MMMM yyyy hh:mm tt" | Saturday, 21 July 2007 03:00 PM |
| "dddd, dd MMMM yyyy H:mm" | Saturday, 21 July 2007 5:01 |
| "dddd, dd MMMM yyyy h:mm tt" | Saturday, 21 July 2007 3:03 PM |
| "dddd, dd MMMM yyyy HH:mm:ss" | Saturday, 21 July 2007 15:04:10 |
| "MM/dd/yyyy HH:mm" | 07/21/2007 15:05 |
| "MM/dd/yyyy hh:mm tt" | 07/21/2007 03:06 PM |
| "MM/dd/yyyy H:mm" | 07/21/2007 15:07 |
| "MM/dd/yyyy h:mm tt" | 07/21/2007 3:07 PM |
| "MM/dd/yyyy HH:mm:ss" | 07/21/2007 15:09:29 |
| "MMMM dd" | July 21 |
| "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK" | 2007-07-21T15:11:19.1250000+05:30 |
| "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'" | Sat, 21 Jul 2007 15:12:16 GMT |
| "yyyy'-'MM'-'dd'T'HH':'mm':'ss" | 2007-07-21T15:12:57 |
| "HH:mm" | 15:14 |
| "hh:mm tt" | 03:14 PM |
| "H:mm" | 5:15 |
| "h:mm tt" | 3:16 PM |
| "HH:mm:ss" | 15:16:29 |
| "yyyy'-'MM'-'dd HH':'mm':'ss'Z'" | 2007-07-21 15:17:20Z |
| "dddd, dd MMMM yyyy HH:mm:ss" | Saturday, 21 July 2007 15:17:58 |
| "yyyy MMMM" | 2007 July |
+----------------------------------------------+--------------------------------------+
Your code also has problems, an ideal code follows:
void LoadRepeater()
{
string sqlStr = "SELECT * FROM tests ORDER BY id";
string connStr = "Server=localhost;Database=dbs;Uid=root;Pwd=senha;";
using (MySqlConnection connect = new MySqlConnection(connStr))
using (MySqlCommand command = new MySqlCommand(sqlStr, connect))
{
connect.Open();
using (MySqlDataReader reader = command.ExecuteReader())
{
DataTable items = new DataTable();
items.Load(reader);
RptList.DataSource = items;
RptList.DataBind();
}
}
}
use a class Mysqldataadapter has several negative aspects, one of them is performance the other is that this class does a lot of things that are not needed.
The answer came true?
– novic