Reputation: 62
I am passing a DateTime value from SQL Table to a Textbox in ASP.Net using
<asp:TextBox ID="dateTxt" runat="server" Text='<%# Eval("date").ToString()%>' class="form-control"></asp:TextBox>
The Value in SQL is 2023-02-08 16:01:49.153
But shows in the textbox as 2/8/2023 09:07:13 PM
I want it to show as the exact SQL value.
This is how I get the value from the Database
SqlCommand cmd = new SqlCommand("SELECT * FROM ThisTable where stage = 'pending'", con)
{
CommandType = CommandType.Text
};
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
Upvotes: 1
Views: 96
Reputation: 101
I have used this it works for me
Text='<%# Eval("date").ToString("yyyy-MM-dd hh:mm:ss")%'
Upvotes: 1
Reputation: 62
I needed to add
Text='<%# Eval("date", "{0:yyyy-MM-dd HH:mm:ss.fff}") %>'
and that worked for me.
Upvotes: 0