Wednesday, February 29, 2012

mvc format databound datetime column

if you want something like "22/11/2012 15:00" then use
columns.Bound(o => o.MyDateTimeValue).Format("{0:dd/MM/yyyy HH:mm}").Width(120);

if you want something like "22/11/2012 3:00 PM" then use
columns.Bound(o => o.MyDateTimeValue).Format("{0:dd/MM/yyyy hh:mm tt}").Width(120);

Tuesday, February 28, 2012

t-sql add new line in code

i keep forgetting this simple solution:
char(13)
now I save it here so that I never forget again

Tuesday, February 14, 2012

c# split multi-line postal address

I have a multi-line postal address (string PostalAddressString) like this:

Address1:12 Garden Street
Address2:
Suburb:Abc
PostCode:123
State:BC
Country:ABCDE


In order to separate details and access them individually i need to do this:



NameValueCollection lines = new NameValueCollection();
string[] TempArray = PostalAddressString.Split(Environment.NewLine.ToCharArray());
if (TempArray.Count() > 5 || TempArray[0].ToLower() != "n/a")
{
foreach (string line in TempArray)
{
string[] parts = line.Split(':');
if (line.Length > 0)
lines.Add(parts[0].Trim(), parts[1].Trim());
}

string PostalAddressLine1String = lines.Get("Address Line 1");
string PostalAddressLine2String = lines.Get("Address Line 2");
string PostalSuburbString = lines.Get("Suburb");
string PostalPostCodeString = lines.Get("PostCode");
string PostalStateString = lines.Get("State");
string PostalCountryString = lines.Get("Country");
}

Thursday, February 09, 2012

Telerik RadGrid how to bind detailtable from code behinde

Use this method:

OnDetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)

The ParentKeyValues can be accessed this way:

e.DetailTableView.ParentItem.GetDataKeyValue("StoreId")

Tuesday, February 07, 2012

t-sql update table with join


update d
set d.dname = "HR"
from Department d
inner join employee e
on e.employeeID = d.employeeID
where d.departmentID = 1