About Me

My photo
a Dynamic and Energetic guy.....

Thursday, November 11, 2010

Usefull .NET code stuff

Show only the short time in a grid
<%# String.Format("{0:g}", Eval("ShuffleTime")) %>  eg:- 22/11/2010 3:39 PM

There are so many useful formats
<%# String.Format("{0:d}", Eval("ShuffleTime")) %>  eg:- 22/11/2010

<%# String.Format("{0:G}", Eval("ShuffleTime")) %>  eg:- 22/11/2010 3:39:55 PM

<%# String.Format("{0:M}", Eval("ShuffleTime")) %>  eg:- November 22

<%# String.Format("{0:t}", Eval("ShuffleTime")) %>  eg:- 11:05 AM


Bind a DataSet/DataTable directly to a DropDown

            DataSet dsUnitTypes = ((PageBase)(this.Page)).Services.Game.GetCodeValuesForCodeHeaderName("UnitType");
            ddlGameTypes.DataSource = dsUnitTypes.Tables[0];
            ddlGameTypes.DataTextField = "Description";
            ddlGameTypes.DataValueField = "CodeID";
            ddlGameTypes.DataBind();

My Masters