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 asp.net, 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:-
CREATE TABLE SqlTest
(
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 asp.net 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"> 
    window.open("default.aspx");
</script>

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 window.open 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;

                    context.Response.Clear();

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

                    context.Response.Write(Environment.NewLine);

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

                    context.Response.ContentType = "text/vnd.ms-excel";
                    context.Response.AppendHeader("Content-Disposition", attachment);
                    context.Response.End();
                }
                else
                {
                    lblMessage.Text = "No Records Found";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }

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

Sunday 9 September 2012

check all checkbox in gridview in asp.net

 //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)  
      Counter++;  
     else if(Counter > 0)  
      Counter--;  
     //Change state of the header CheckBox.  
     if(Counter < TotalChkBx)  
      HeaderCheckBox.checked = false;  
     else if(Counter == TotalChkBx)  
      HeaderCheckBox.checked = true;  
   }  
     </script>