cant format datetime using dataformatstring - asp.net

For some reason i can not format the text of my date in a gridview
<asp:BoundField DataField="deptdate" HeaderText="Departure Date" dataformatstring="{0:ddd, MM/d/yyyy}" htmlencode="False" SortExpression="deptdate" />
I still get this:
May 10 2011 12:00AM
I DID NOT SET MY FIELD TO DATETIME IN THE DATABASE...DOY

Have you tried this approach?
http://peterkellner.net/2006/05/24/how-to-set-a-date-format-in-gridview-using-aspnet-20using-htmlencode-property/
<asp id="GridView1" runat="server" :GridView>
<columns>
<asp headertext="CreationDate" dataformatstring="{0:M-dd-yyyy}"
datafield="CreationDate" :BoundField HtmlEncode="false" />
</columns>

You can use DataFormatString="{0:d}" for short date format in your column definition.

Since Q2 2013 the RadHtmlChart can be databound to DateTime objects, so that XAxis Labels, Series Labels and ToolTips can be formatted to the desired date format. More information on formatting dates is available in Date Axis article: http://www.telerik.com/help/aspnet-ajax/htmlchart-date-axis.html

Related

How to disable past dates in GridViewDataDateColumn in aspxgridview

<dx:GridViewDataDateColumn FieldName="ScheduledTimeForDelivery" Caption="Scheduled Time For Delivery" Width="14%" VisibleIndex="5">
<Settings AutoFilterCondition="Contains" />
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="True" Wrap="True" />
<PropertiesDateEdit DisplayFormatString="dd/MM/yyyy hh:mm tt" EditFormatString="dd/MM/yyyy hh:mm tt">
<TimeSectionProperties Visible="true">
<TimeEditProperties EditFormatString="hh:mm tt" EditFormat="Custom"></TimeEditProperties>
</TimeSectionProperties>
<ValidationSettings RequiredField-IsRequired="true" ErrorTextPosition="Bottom" ErrorDisplayMode="Text">
<RequiredField ErrorText="Please enter the Scheduled Time For Delivery" />
</ValidationSettings>
</PropertiesDateEdit>
<EditFormSettings VisibleIndex="3" />
</dx:GridViewDataDateColumn>
I want to disable all previous dates in my Column"ScheduledTimeForDelivery" how to disable it previous dates.
Reference: ASPxGridview - date column
Use the editor's MaxDate and MinDate properties for this purpose. For example:
GridViewDataDateColumn dateColumn = gridView.Columns["ScheduledTimeForDelivery"] as GridViewDataDateColumn;
dateColumn.PropertiesDateEdit.MaxDate = System.DateTime.Now.AddYears(5);
dateColumn.PropertiesDateEdit.MinDate = System.DateTime.Now.AddYears(-5);
Or you can manage to do it in aspx page also with help of documentation..
Disabling specific dates in ASPxDateEdit, in Edit form of ASPxGridView
Hope this help..
use this line in cell editor initialize even
if (e.Column.FieldName == "ScheduledTimeForDelivery")
(e.Editor as ASPxDateEdit).MinDate = DateTime.Now.Date;

data format string in grid view asp.net c#

Is there some way I can use a data format string in a bound field which appends % to my value ?
Example :
For rupee we can do this :
<asp:BoundField DataField="PassPercent" ItemStyle-Width="7%" HeaderText="Pass Percent" DataFormatString="{0:c}"
I tried using a template field too but that didn't work :
<asp:TemplateField HeaderText="Pass Percent" ItemStyle-Width="5%" >
<ItemTemplate>
<asp:Label runat="server" DataValueField="PassPercent" DataTextField="PassPercent" />
<asp:Label Text="%" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Try this:-
DataFormatString="{0:p}"
But, please note percentages are stored as decimals in this case so you need to adjust your values accordingly. Check the formatting's here on MSDN.
Or you can simply hard-code it:-
DataFormatString="{0}%"

ajax calender extender month name display

i have added an extender to the text box to select date. The date it shows the number of the corresponing month. is there any way to get the month name instead of the month number? for eg i get as 04-04-13 i want it as 04-Apr-13. Thanks in advance
the code i have is
<asp:TextBox ID="txtInvDate" runat="server" Height="21px" Width="88px"
ontextchanged="txtInvDate_TextChanged" AutoPostBack="True"></asp:TextBox>
<asp:CalendarExtender ID="txtInvDate_CalendarExtender"
runat="server" TargetControlID="txtInvDate" Format="dd-MM-yyyy">
</asp:CalendarExtender>
You could try following format:
<asp:CalendarExtender ID="txtInvDate_CalendarExtender" runat="server" TargetControlID="txtInvDate"
Format="dd-MMM-yyyy" >
</asp:CalendarExtender>
Custom Date and Time Format Strings
particularly: The "MMM" Custom Format Specifier
Note that it depends on the current culture on the server.

I want to represent weekdays in a gridview

<asp:GridView ID="grid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField='id' HeaderText="Id" Visible="False" />
<asp:BoundField DataField='Name' Visible="True" HeaderText="Full Name"/>
<asp:BoundField HeaderText="Monday" />
<asp:BoundField HeaderText="Tuesday" />
<asp:BoundField HeaderText="Wednesday" />
<asp:BoundField HeaderText="Thursday" />
<asp:BoundField HeaderText="Friday" />
</Columns>
</asp:GridView>
<asp:TextBox ID="tbFirstDate" runat="server"></asp:TextBox>
//In the DataTable that is the source for this grid1 I have a column 'date', but in the Grid I need to show weekday with that date (ex. Monday 20.08.2012). I also have a TextBox(tbFirstDate) that defines which day is monday, so using that info I need to calculate the rest of the weekdays, date format is yyyy-mm-dd
I work with PostreSQL, this is the SQL query:
SELECT * FROM Table1
WHERE id1=212 AND date BETWEEN '20.08.2012' AND '24.08.2012'
ORDER BY date
Now this result I want to represent in the grid like this
So basically your actual question is how to change a DateTime's DayOfWeek value by it's distance to a specified first day of week?
Then you could use this method:
public static int Weekday(DateTime dt, DayOfWeek startOfWeek)
{
return (dt.DayOfWeek - startOfWeek + 7) % 7;
}
For example, assuming that the user entered today to specify that Tuesday is the beginning of the week:
DateTime value = new DateTime(2012, 8, 20);
DayOfWeek weekday = (DayOfWeek)Weekday(value, DateTime.Now.DayOfWeek);
Console.Write("normally:{0} changed to:{1}", value.DayOfWeek, weekday);
Demo: http://ideone.com/Zk99b
If this is true you only have to use this method in RowDataBound of the GridView to set the Text of a Label in a TemplateField manually according to the specified date in tbFirstDate and the date value in the DataItem of the GridViewRow. Use GridViewRow.FindControl("LabelID") to get a reference to the Label.

Using a CalendarExtender with a MaskedEditExtender

I'm trying to have a textbox function exactly like the third textbox down on this page: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/MaskedEdit/MaskedEdit.aspx. I'm trying to use a CalendarExtender control with a MaskedEditExtender, because I don't want the user to be able to enter anything except a valid date into the box. On my maskededitextender I have a mask of "99/99/9999" but it seems to only work when the date is actually 8 digits (e.g. 12/12/2000) and not when the date is 7 or 6 digits (e.g. 1/1/2000 or 1/14/2000). The mask screws up when the date is less than 8 digits. Here is my code:
<asp:TextBox runat="server" ID="txtDateAvailable" Width="150px" maxlength="50"></asp:TextBox>
<asp:CalendarExtender ID="calDateAvailable" runat="server" TargetControlID="txtDateAvailable" format="d" PopupPosition="Right"></asp:CalendarExtender>
<asp:MaskedEditExtender ID="mskDateAvailable" runat="server" targetcontrolid="txtDateAvailable" Mask="99/99/9999" clearmaskonlostfocus="false" MaskType="None"></asp:MaskedEditExtender>
If I could figure out how to get the date format of the CalendarExtender to MM/DD/YYYY instead of just M/D/YYYY that would fix it.
There is a Format property of Calendar Control. Use that to set to
Format="MM/dd/yyyy"
The syntax for it is as follows: Format="MM/dd/yyyy" and change it around as you wish, but you must ensure that the month is in uppercase otherwise it will return zeros i used -
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"
PopupButtonID="ImageButton1" Format="dd/MM/yy">

Resources