Tuesday 20 September 2011

How to print notepad content in asp.net page

If you want to print the notepad content in the aspx page then you can do in the following ways.

Step-1 :  Take a lable on the page.
Step-2 : In the aspx.cs file add the in the above.
                          using System.IO;
Step-3 : In the page load write the following
         
              lblReadContent.Text = ReadFile(Server.MapPath("~/articles.txt"));
Step-4 : Create a function ReadFile which will return string.        
              public string ReadFile(string strFileName)
             {    
                  StreamReader fp=null;
                  string returnText;
                  try
                 {
                           fp = File.OpenText(strFileName);
                           returnText= fp.ReadToEnd();
                           fp.Close();
                 }
                catch
                {
                          returnText = "";
                }
                return returnText;
      }


Sunday 18 September 2011

Delete duplicate rows


SET ROWCOUNT 1
delete emp from emp a where (select count(*) from emp b where a.name=b.name) >1
WHILE @@rowcount > 0
delete emp from emp a where (select count(*) from emp b where a.name=b.name) >1
SET ROWCOUNT 0

or


DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)

or



WITH empTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY EmpName,Position ORDER BY EmpName) As RowNumber,* FROM emp
)
DELETE FROM  empTable  where RowNumber >1
SELECT * FROM emp order by Id asc

Display row by Radio button selected change


function DisplayRowonRbl()
{     
     var trDesignation= document.getElementById('<%=trDesignation.ClientID%>');
     var tblDepartment= document.getElementById('<%=tblDepartment.ClientID%>');
      var s=document.getElementById('<%=rbnDepartment.ClientID%>');
      var s1=s.getElementsByTagName('input');
      for (var i = 0; i < s1.length; i++)
      {
          if (s1[i].checked && s1[i].value=='Others')
          {
                trDesignation.style.display = '';
                tblDepartment.style.display = 'none';
           }
           else
           {
                  tblDepartment.style.display = '';
                  trDesignation.style.display = 'none';
                 }
            }
   }

Call the above method on the selected change properties of radiobutton.

Friday 9 September 2011

Open a new window in pop up with print option


Call the below function in the OnClientClick of the button.

<script language="javascript">
function Clickheretoprint()
{
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25";
  var content_vlue = document.getElementById("print_content").innerHTML;
 
  var docprint=window.open("","",disp_setting);
   docprint.document.open();
   docprint.document.write('<html><head><title>Home Page</title>');
   docprint.document.write('</head><body onLoad="self.print()"><center>');        
   docprint.document.write(content_vlue);        
   docprint.document.write('</center></body></html>');
   docprint.document.close();
   docprint.focus();
}
</script>