Wednesday, February 19, 2014

Prevent table row onclick event to fire when clicking button inside the row

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script type="text/javascript">
      function test(e) {
         alert('button');
         e.stopPropagation();
      }
   </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <table border="1" cellpadding="0" cellspacing="0">
          <tr onclick="javascript:alert('li')" style="cursor:pointer">
             <td>
             <input  type="button" onclick="test(event)" value="click me" />
             </td>
             <td>ll</td>
          </tr>
       </table>
    </div>
    </form>
</body>
</html>

Friday, February 7, 2014

SQL Update table column if parameter has value in sigle update statement



CREATE TABLE test2(clm1 INT,clm2 INT)

INSERT INTO test2 VALUES(1,1)
INSERT INTO test2 VALUES(2,2)
INSERT INTO test2 VALUES(3,3)
INSERT INTO test2 VALUES(4,4)


DECLARE @par1 INT = 100;
DECLARE @par2 INT = NULL;

UPDATE test2
SET clm1 = COALESCE(@par1,clm1)
,clm2 = COALESCE(@par2,clm2)

WHERE clm1 = 1

SELECT * FROM test2

DROP TABLE test2