0

I have a GridView with LinqtoSQL data source.I am binding it in code.Here is the code

 DataClassesDataContext dContext = new DataClassesDataContext();
            var userId = (Guid)(Membership.GetUser(Membership.GetUser().UserName, false).ProviderUserKey);
            var Query = from d in dContext.table1
                              where d.UserId == userId
                              select new { d.date, d.weight, d.height, d.BMI };


            gv.DataSource = Query;
            gv.DataBind();

the d.date is DateTime column I like to show only the date how to format it? Thanks

3 Answers 3

1

code in aspx page

<asp:GridView ID="gridView1" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField DataField="Login_USER" HeaderText="Login User" />
                    <asp:BoundField DataField="Login_DATE" HeaderText="Login Date"
                        DataFormatString="{0:MM/dd/yyyy}" />
                </Columns>
            </asp:GridView>

======================================

code

Entities db = new Entities();

var users = from user in db.Logged_user select new {user.Login_USER, user.Login_DATE };

if(users != null)
{
     gridView1.DataSource = branches.ToList();
     gridView1.DataBind();
}
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to Stack Overflow! If you could please edit your answer and explain what the code you're showing does, and why/how that code answers the question, it would make your answer even more helpful.
0

One of the ways to convert DateTime to show only date is this one

DateTime today=DateTime.Now;
string todayString=today.ToString();
string dateOnly=todayString.Split(' ')[0];

Comments

0
var Query = from d in dContext.table1 
            where d.UserId == userId 
            select new { date = String.Format("{0:MM/dd/yyyy}", d.date), d.weight, d.height, d.BMI };

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.