Pages

Friday, June 3, 2011

DateTime Format in GridView ItemTemplate In Asp.net C#

DateTime Format in GridView ItemTemplate In Asp.net C#

To format DateTime in GridView In ItemTemplate we have to pass format in eval or bind . There are many format available for the
DateTime .In this article i have given some example that how to format datetime and at end i have listed the datetime format
used in gridview .

Following are  the examples of ItemTemplate where format used for datetime .

<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date", "{0:dd/MM/yyyy}")%>' ></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="lblDat1" runat="server" Text='<%# Eval("Date", "{0:D}")%>' ></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

Following are  the examples of BoundFieldwhere format used for datetime .

<asp:boundfield datafield="DOB" dataformatstring="{0:d}" headertext="Date Of Birth" readonly="True"> </asp:boundfield>

The following table shows some date format strings that can be used to format date in GridView columns,

Format Pattern Name Example
d Short date 11/8/2008
D Long date Sunday, August 11, 2008
t Short time 3:32 PM
T Long time 3:32:00 PM
f Full date/time (short time) Sunday, August 11, 2008 3:32 PM
F Full date/time (long time) Sunday, August 11, 2008 3:32:00 PM
g General date/time (short time) 8/11/2008 3:32 PM
G General date/time (long time) 8/11/2008 3:32:00 PM
m or M Month day August 11
r or R RFC 1123 Sun, 11 Aug 2008 8:32:00 GMT
s Sortable date/time 2008-08-11T15:32:00
u Universable sortable date/time 2008-08-11 15:32:00z
U Universable sortable date/time Sunday, August 11, 2008 11:32:00 PM
y or Y Year month August, 2008


Related Other posts

Thursday, June 2, 2011

Find all references Of Object Table , Stored Procedures, Scalar function In sql Server

Find all references Of Object Table , Stored Procedures, Scalar function In sql Server

Following is the query by which you can get all references of object  Like Table , Stored procedures ,Scalar function ..etc In Scalar function ,Trigger ,View ,stored procedure ..etc.

Many times we require that find all stored procedures that reference a given table .

By Following to search all objects in a database containing a certain string .

SELECT DISTINCT o.name AS ObjectName,
CASE o.xtype
WHEN 'C' THEN 'CHECK constraint'
WHEN 'D' THEN 'Default or DEFAULT constraint'
WHEN 'F' THEN 'FOREIGN KEY constraint'
WHEN 'FN' THEN 'Scalar function'
WHEN 'IF' THEN 'In-lined table-function'
WHEN 'K' THEN 'PRIMARY KEY or UNIQUE constraint'
WHEN 'L' THEN 'Log'
WHEN 'P' THEN 'Stored procedure'
WHEN 'R' THEN 'Rule'
WHEN 'RF' THEN 'Replication filter stored procedure'
WHEN 'S' THEN 'System table'
WHEN 'TF' THEN 'Table function'
WHEN 'TR' THEN 'Trigger'
WHEN 'U' THEN 'User table'
WHEN 'V' THEN 'View'
WHEN 'X' THEN 'Extended stored procedure'
ELSE o.xtype
END AS ObjectType,
ISNULL( p.Name, '[db]') AS Location
FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id
LEFT JOIN sysobjects p ON o.Parent_obj=p.id
WHERE c.text LIKE '%any text to search for%'
ORDER BY Location, ObjectName

If pass table object name then it show all references table in Stored procedures ,Scalar function ..etc .
If pass Stored procedure object name then it show all references Stored procedures in Stored Procedures ..etc .


Related Other posts

String was not recognized as a valid Boolean In C#

String was not recognized as a valid Boolean In C# .

Introduction : In this article i will show how to resolve the error string was not recognized as a valid Boolean in . Its very easy to resolve .just you need to create one method .Pass the string to method then it will return Boolean .

Method for valid Boolean :
    private static bool GetBoolean(string strValue)
    {
        if (strValue=="1")
            return true;
        else
            return false;
    }

Call the function :
 GetBoolean(stringValue) ;

Related Other posts