Sunday, 30 September 2012

Disable Copy Paste In Textbox In Asp.Net

If we want to allow users to use right click to copy paste or by using ctrl+C , ctrl+v in textbox on a aspx page in, To disable this we can use javascript
we can achieve this in 2 ways
use Following method If u don't want any alerts or message

If you want to show alerts than use Following method
Right this javascript function in the head section of aspx page, in this function we are disabling right mouse click and ctrl keys

Untitled Page

Wednesday, 26 September 2012

sql interview questions

Hello Every one, This post demonstrates some commonly asked SQL queries in a job interview. I will be covering some of the common but tricky queries like:-
*) Finding the nth highest salary of an employee.
Create a table named SqlTest and insert some test data as:-
ID INT Identity,
Name Varchar(100),
Sal Decimal (10,2)

INSERT INTO SqlTest VALUES ('Chetan',1000);
INSERT INTO SqlTest VALUES ('Shilpa',1200);
INSERT INTO SqlTest VALUES ('Surya',1100);
INSERT INTO SqlTest  VALUES ('Kanchan',1300);
INSERT INTO SqlTest  VALUES ('Amit',1400);

First We Find Highest Salary To find the highest salary as
--Find  Highest Salary
select max(Sal) from SqlTest 

Friday, 21 September 2012

C sharp code formatter in Blog

You Can Download it From This Blog from following link
C Sarp Formatter
Thank you Chetan Virkar

Bulk Insert into SQL Server Using SqlBulkCopy In Asp.Net

Hi All, we are using excel sheet to store the data but nowdays we want to store the excel sheet data into database. therefore in there is SqlBulkCopy to store excel sheet data into table of database directly . Folllowing Are Step to BulkInsert In database through Excel Sheet.
Step 1 : Create Table in database
create table Test
id int,
name varchar(50),
address varchar(100),
CreatedBy varchar(100)

Friday, 14 September 2012

Response.Redirect into a new window

The only way to open a new window is for it to be initiated on the client side, whether it be through script or clicking on a link.
So the solution always proposed to this problem is to instead write out some script that opens the window, rather than using Response.Redirect:

<script type="text/javascript">"default.aspx");

Now the helper method which is used for redirecting to new page.
It's easy enough to write a little helper that abstracts the details away from us... while we're at it, we might as well add target and window Features parameters. If we're going to open the new window with script, why not let you use all of the parameters? For example, with window Features you can specify whether the new window should have a menu bar, and what its width and height are.

Thursday, 13 September 2012

Export to DataTable To Excel Using Asp.Net

Here Your ds contain the DataTable to which you want to export in excel-sheet format
  if (ds.Tables.Count > 0)
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                    string attachment = "attachment; filename=PenaltyRiskReport.xls";
                    HttpContext context = HttpContext.Current;


                    foreach (DataColumn column in dt.Columns)
                        context.Response.Write(column.ColumnName + "\t");


                    foreach (DataRow row in dt.Rows)
                        for (int i = 0; i < dt.Columns.Count; i++)
                            context.Response.Write(row[i].ToString() + "\t");

                    context.Response.ContentType = "text/";
                    context.Response.AppendHeader("Content-Disposition", attachment);
                    lblMessage.Text = "No Records Found";
                    lblMessage.ForeColor = System.Drawing.Color.Red;

                lblMessage.Text = "No Records Found";
                lblMessage.ForeColor = System.Drawing.Color.Red;

Sunday, 9 September 2012

check all checkbox in gridview in

 //Javascript Code  
<script type="text/javascript">  
   var TotalChkBx;  
   var Counter;  
   window.onload = function()  
     //Get total no. of CheckBoxes in side the GridView.  
     TotalChkBx = parseInt('<%= this.gvwDetail.Rows.Count %>');  
     //Get total no. of checked CheckBoxes in side the GridView.  
     Counter = 0;  
   function HeaderClick(CheckBox)  
     //Get target base & child control.  
     var TargetBaseControl =  
       document.getElementById('<%= this.gvwDetail.ClientID %>');  
     var TargetChildControl = "chkBxSelect";  
     //Get all the control of the type INPUT in the base control.  
     var Inputs = TargetBaseControl.getElementsByTagName("input");  
     //Checked/Unchecked all the checkBoxes in side the GridView.  
     for(var n = 0; n < Inputs.length; ++n)  
      if(Inputs[n].type == 'checkbox' &&  
           Inputs[n].id.indexOf(TargetChildControl,0) >= 0)  
        Inputs[n].checked = CheckBox.checked;  
     //Reset Counter  
     Counter = CheckBox.checked ? TotalChkBx : 0;  
   function ChildClick(CheckBox, HCheckBox)  
     //get target control.  
     var HeaderCheckBox = document.getElementById(HCheckBox);  
     //Modifiy Counter;  
     if(CheckBox.checked && Counter < TotalChkBx)  
     else if(Counter > 0)  
     //Change state of the header CheckBox.  
     if(Counter < TotalChkBx)  
      HeaderCheckBox.checked = false;  
     else if(Counter == TotalChkBx)  
      HeaderCheckBox.checked = true;