.Net Links

Thursday, January 20, 2011

Trim function in Javascript

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

function trim() {
return this.replace(/^\s+|\s+$/g, '');
}
Add the above lines and call the trim function which would trim the leading and trailing spaces in the variable Password


var Password = document.getElementById('ctl00_cphBody_txtPassword').value;
Password = Password.trim();

Labels: , ,

Enabling / Disabling .Net Validation Controls in Javascript

The below piece of code will help to enable for disable validation controls in .Net



var myValidator1 = document.getElementById('ctl00_cphBody_ReqFldValid');
ValidatorEnable(myValidator1, bool);

The ValidatorEnable contains two parameters.The first is for passing the Control ID and the other a boolean variable True or False to make it enable or disable

Labels: ,

Tuesday, January 11, 2011

Multiple insert using one insert statement in SQL 2008

Multiple insert using one statement in SQL 2008

Insert all records into table using the Row constructor

INSERT INTO USER(ID, NAME)
VALUES(1,'userA'),
(2,'userB'),
(3,'userC'),
(4,'userD'),
(5,'userE'),
(6,'userF'),
(7,'userG'),
(8,'userH'),
(9,'userI'),
(10,'userJ')

Labels: ,

Friday, January 7, 2011

Binding Values in Grid

http://www.15seconds.com/issue/040630.htm

Labels: , ,

Tuesday, January 4, 2011

Loading XML document from a SqlDataReader

SqlConnection sqlconn = new SqlConnection(@"Data Source=ABC;Initial Catalog=ABC;Integrated Security=SSPI;Trusted_Connection=True");
SqlCommand command = new SqlCommand("SPName", sqlconn);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "SPName";
command.Connection = sqlconn;
sqlconn.Open();

SqlDataReader dr = command.ExecuteReader();

DataTable dt = new DataTable();
dt.Load(dr);

XmlDocument xmlDocument = new XmlDocument();
StringBuilder sb = new StringBuilder();

sb.Append("");
sb.Append("");

foreach (DataRow dataRow in dt.Rows)
{
foreach (DataColumn dataColumn in dt.Columns)
sb.Append("<" + dataColumn.ColumnName + ">" +
dataRow[dataColumn].ToString() +
"");


}

sb.Append("
");
xmlDocument.LoadXml(sb.ToString());

Labels: ,