function HasAlpha(Txt)
{
strLen = Txt.length;
for(i=0; i < strLen;i++)
{
if((Txt.charAt(i)<"0") || (Txt.charAt(i)>"9"))
{
return true;
}
}
return false;
}
Monday, October 27, 2008
Saturday, October 25, 2008
How to open sql Connection ?
private string sqlString = "Data Source=Server_Name;Initial Catalog=Database_Name;Integrated Security=SSPI;";
private SqlConnection sqlConn;
if (sqlConn.State != ConnectionState.Closed)
{
sqlConn.Close();
}
sqlConn = new SqlConnection(sqlString);
sqlConn.Open();
/*
Standard Security:
1.
"Data Source=Server_Name;Initial Catalog= Database_Name;UserId=Username;Password=Password;"
2.
"Server=Server_Name;Database=Database_Name;
UserID=Username;Password=Password;Trusted_Connection=False"
Trusted connection:
1. "Data Source=Server_Name;Initial Catalog=Database_Name;Integrated Security=SSPI;"
2."Server=ServerName;Database=Database_Name;
Trusted_Connection=True;"
*/
private SqlConnection sqlConn;
if (sqlConn.State != ConnectionState.Closed)
{
sqlConn.Close();
}
sqlConn = new SqlConnection(sqlString);
sqlConn.Open();
/*
Standard Security:
1.
"Data Source=Server_Name;Initial Catalog= Database_Name;UserId=Username;Password=Password;"
2.
"Server=Server_Name;Database=Database_Name;
UserID=Username;Password=Password;Trusted_Connection=False"
Trusted connection:
1. "Data Source=Server_Name;Initial Catalog=Database_Name;Integrated Security=SSPI;"
2."Server=ServerName;Database=Database_Name;
Trusted_Connection=True;"
*/
Monday, October 20, 2008
How to iterate through datagrid items with paging ?
Suppose I have one DataGrid with one item column with CheckBox chk_Select. I want
to check the checked record and want to process it.
for (int cnt = 0; cnt < DataGrid.PageCount; cnt++)
{
DataGrid.CurrentPageIndex = cnt;
DataGrid.DataSource=ds;
DataGrid.DataBind();
for (int i = 0; i < DataGrid.Items.Count; i++)
{
CheckBox chk_Select = (CheckBox)DataGrid.Items[i].FindControl("chk_Select");
if (chk_Select.Checked)
{
//Process the row here
}
}
}
to check the checked record and want to process it.
for (int cnt = 0; cnt < DataGrid.PageCount; cnt++)
{
DataGrid.CurrentPageIndex = cnt;
DataGrid.DataSource=ds;
DataGrid.DataBind();
for (int i = 0; i < DataGrid.Items.Count; i++)
{
CheckBox chk_Select = (CheckBox)DataGrid.Items[i].FindControl("chk_Select");
if (chk_Select.Checked)
{
//Process the row here
}
}
}
Friday, October 17, 2008
Wednesday, October 15, 2008
How to get element in child window in javascript ?
***Parent Form Coding Parent.html
(html)
(body)
(input type='text' id='txtName')
(input type='button' id='btnOk' value='Ok'
onClick='window.open("Child.html","Child")')
(/body)
(/html)
***Child Form Coding Child.html
(html)
(head)
(script language='javascript')
function Show()
{
var test = window.opener.document.getElementById("txtName");
alert(test.value);
}
(/script)
(/head)
(body onLoad='Show()')
(/body)
(/html)
Note : Please replace () with <> for every html tags
(html)
(body)
(input type='text' id='txtName')
(input type='button' id='btnOk' value='Ok'
onClick='window.open("Child.html","Child")')
(/body)
(/html)
***Child Form Coding Child.html
(html)
(head)
(script language='javascript')
function Show()
{
var test = window.opener.document.getElementById("txtName");
alert(test.value);
}
(/script)
(/head)
(body onLoad='Show()')
(/body)
(/html)
Note : Please replace () with <> for every html tags
Monday, October 13, 2008
Export Data From DataGrid To Excel
DataGrid.AllowPaging = false; //cancel paging if there is
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=" + "FileNameToExportIn");
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
ClearControls(DataGrid);
DataGrid.AllowPaging = false;
DataGrid.DataSource=ds; //Bind Grid Again
DataGrid.DataBind();
//To Show Grid Lines
DataGrid.GridLines = GridLines.Both;
//To Format Header With Color
DataGrid.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
DataGrid.RenderControl(htw);
DataGrid.AllowPaging = true;
DataGrid.DataSource=ds; //Bind Grid Again
DataGrid.DataBind();
Response.Write(sw.ToString());
Response.End();
DataGrid.AllowPaging = true;
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=" + "FileNameToExportIn");
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
ClearControls(DataGrid);
DataGrid.AllowPaging = false;
DataGrid.DataSource=ds; //Bind Grid Again
DataGrid.DataBind();
//To Show Grid Lines
DataGrid.GridLines = GridLines.Both;
//To Format Header With Color
DataGrid.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
DataGrid.RenderControl(htw);
DataGrid.AllowPaging = true;
DataGrid.DataSource=ds; //Bind Grid Again
DataGrid.DataBind();
Response.Write(sw.ToString());
Response.End();
DataGrid.AllowPaging = true;
Wednesday, October 8, 2008
Error Handling In Sql Server
Error_Number()
Returns the error number of the error that caused the CATCH block of a TRY…CATCH construct to be run in Sql Server. Return type of this function is int.
Error_Line()
Returns the line number at which an error occurred in Sql Server Stored Procedure..
Error_Message()
Returns the message text of the error that occured in Sql Server Stored Procedure.
Example :
BEGIN TRY
SELECT 1/0; --Divide by zero error
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrNumber;
SELECT ERROR_LINE() AS ErrLine;
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH
Returns the error number of the error that caused the CATCH block of a TRY…CATCH construct to be run in Sql Server. Return type of this function is int.
Error_Line()
Returns the line number at which an error occurred in Sql Server Stored Procedure..
Error_Message()
Returns the message text of the error that occured in Sql Server Stored Procedure.
Example :
BEGIN TRY
SELECT 1/0; --Divide by zero error
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrNumber;
SELECT ERROR_LINE() AS ErrLine;
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH
Tuesday, October 7, 2008
Difference inline and code behind
Inline code written along side the html in a page. Code behind is code written in a seperate file and referenced by the aspx page.
Friday, October 3, 2008
Difference Between Varchar And NVarchar
The difference between the two is that Nvarchar is used to store uNicode data, which is used to store multilingual data in your database tables. Other languages like chinese have an extended set of character codes that needs to be saved and this datatype allows for this extension.
If your database will not be storing multilingual data you should use the varchar datatype instead of nvarchar datatype. Because nvarchar takes twice as much space as varchar.
If your database will not be storing multilingual data you should use the varchar datatype instead of nvarchar datatype. Because nvarchar takes twice as much space as varchar.
Subscribe to:
Posts (Atom)