troubleshooting Question

ASP.net Gridview date format

Avatar of jaytechnology
jaytechnologyFlag for Afghanistan asked on
ASP.NETVB ScriptMicrosoft Development
8 Comments1 Solution896 ViewsLast Modified:
I am running vs2010 .net 4.0.  I have a gridview with several bound columns and it is an update, insert, delete data grid.  There are 3-4 columns that are dates and they are showing the time too.  All I want is they actual date format.  I have tried this but I am not showing asp:BoundField s in my code.
<asp:BoundField HeaderText=”Member Since” DataField=”TimeStamp”
 DataFormatString=”{0:M-dd-yyyy}” />
 </Columns>
<asp:GridView ID="gvProjects" runat="server" AutoGenerateColumns="False" 
            CellPadding="1" DataKeyNames="ID,ProjectName" 
            DataSourceID="dsNewProjectsDataEntry" ForeColor="#333333" GridLines="None" 
            ShowFooter="True" style="text-align: center" EnableModelValidation="True" 
            Font-Size="Small">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update" BackColor="White"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel" BackColor="White"></asp:LinkButton>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:Button ID="btSubmit" runat="server" Text="Submit" 
                            onclick="btSubmit_Click" Height="26px" style="margin-right: 10px" 
                            Width="59px" />
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="Edit" BackColor="White" ForeColor="#003399"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="Delete" BackColor="White" ForeColor="#003399"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" Visible="False"   />
                <asp:TemplateField HeaderText="Project Name" SortExpression="ProjectName">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("ProjectName")  %>'></asp:Label>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="tbProjectName" runat="server" Height="20px" Width="77px"></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        
                     <asp:HyperLink ID="HyperLink1"  runat="server" Text='<%# Eval("ProjectName")%>' Target="_self" NavigateUrl='<%# "NewProjectsBody.aspx?TempID=" & Eval("ID")%>'></asp:HyperLink>

                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Status Date" SortExpression="StatusDate"  >
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server"  Text='<%# Bind("StatusDate")  %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="tbStatusDate" runat="server" Height="20px" Width="77px"></asp:TextBox>
                        <br />
                        <asp:CompareValidator ID="CompareValidator1" runat="server" 
                            ControlToValidate="tbStatusDate" Display="Dynamic" 
                            ErrorMessage="Required Date - yyyy/mm/dd" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
                        
                        
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("StatusDate") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Start Date" SortExpression="StartDate">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("StartDate") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="tbStartDate" runat="server" Height="20px" Width="83px"></asp:TextBox>
                        <br />
                        <asp:CompareValidator ID="CompareValidator11" runat="server" 
                            ControlToValidate="tbStartDate" Display="Dynamic" 
                            ErrorMessage="Required Date -yyyy/mm/dd" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("StartDate") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="End Date" SortExpression="EndDate">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EndDate") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="tbEndDate" runat="server" Height="20px" Width="83px"></asp:TextBox>
                        <br />
                        <asp:CompareValidator ID="CompareValidator12" runat="server" 
                            ControlToValidate="tbEndDate" Display="Dynamic" 
                            ErrorMessage="Required Date - yyyy/mm/dd" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("EndDate") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="% Complete" SortExpression="PercentComplete">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("PercentComplete") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="tbPercent" runat="server" Height="20px" Width="55px"></asp:TextBox>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                            ControlToValidate="tbPercent" Display="Dynamic" ErrorMessage="Required Field"></asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("PercentComplete") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Project Sponsor" SortExpression="ProjectSponsor">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ProjectSponsor") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:SqlDataSource ID="dsSponsor" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ProjectManagementConnectionString %>" 
                            SelectCommand="SELECT * FROM [Users]"></asp:SqlDataSource>
                        <asp:DropDownList ID="ddSponsor" runat="server" DataSourceID="dsSponsor" 
                            DataTextField="pmUser" DataValueField="pmUser" Height="20px" Width="74px">
                        </asp:DropDownList>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                            ControlToValidate="ddSponsor" Display="Dynamic" ErrorMessage="Required Field"></asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label6" runat="server" Text='<%# Bind("ProjectSponsor") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Project Manager" SortExpression="ProjectManager">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("ProjectManager") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:SqlDataSource ID="dsPM" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ProjectManagementConnectionString %>" 
                            SelectCommand="SELECT * FROM [Users]"></asp:SqlDataSource>
                        <asp:DropDownList ID="ddProjectManager" runat="server" DataSourceID="dsPM" 
                            DataTextField="pmUser" DataValueField="pmUser" Height="20px" Width="75px">
                        </asp:DropDownList>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                            ControlToValidate="ddProjectManager" Display="Dynamic" 
                            ErrorMessage="Required Field"></asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%# Bind("ProjectManager") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="IR Director" SortExpression="IRDirector">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("IRDirector") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:SqlDataSource ID="dsIRDirector" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ProjectManagementConnectionString %>" 
                            SelectCommand="SELECT * FROM [Users]"></asp:SqlDataSource>
                        <asp:DropDownList ID="ddDirector" runat="server" DataSourceID="dsIRDirector" 
                            DataTextField="pmUser" DataValueField="pmUser" Height="20px" Width="65px">
                        </asp:DropDownList>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                            ControlToValidate="ddDirector" Display="Dynamic" ErrorMessage="Required Field"></asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("IRDirector") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Status" SortExpression="Status">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:SqlDataSource ID="dsStatus" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ProjectManagementConnectionString %>" 
                            SelectCommand="SELECT * FROM [statusCodes]"></asp:SqlDataSource>
                        <asp:DropDownList ID="ddStatus" runat="server" DataSourceID="dsStatus" 
                            DataTextField="statusCode" DataValueField="statusCode" Height="20px">
                        </asp:DropDownList>
                        <br />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                            ControlToValidate="ddStatus" Display="Dynamic" ErrorMessage="Required Field"></asp:RequiredFieldValidator>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label9" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Open" SortExpression="ProjectOpen">
                    <EditItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" 
                            Checked='<%# Bind("ProjectOpen") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:CheckBox ID="cbOpen" runat="server" />
                        <br />
                        Open ?
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" 
                            Checked='<%# Bind("ProjectOpen") %>' Enabled="false" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

        </asp:GridView>
ASKER CERTIFIED SOLUTION
jaytechnology

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros