Wednesday, June 30, 2010

Function to Select or Deselect all checkbox in a gridview through javascript

<script language="javascript" type="text/javascript" >
function SelectAll(SelBtn)
     {
          var gvET = document.getElementById("GridView1"); 
             var rCount = gvET.rows.length;
             var btnSel = SelBtn.value;
             var rowIdx;
             // check the Page Count is greater than 1 then rowindex will start from 2 else 1
             if(document.getElementById("hidgridpagecount").value>1)
             {
                  rowIdx=2;
             }
             else
             {
                  rowIdx=1;
             }
             for (rowIdx; rowIdx<=rCount-1; rowIdx++)
             {
                  var rowElement = gvET.rows[rowIdx];
                  var chkBox = rowElement.cells[0].firstChild;
                  if (btnSel == 'Select All')
                  {
                       chkBox.checked = true;
                  }
                  else
                  {
                       chkBox.checked = false;
                  }
             }
             if (btnSel == 'Select All')
             {
                  document.getElementById('btnSelAll_Top').value ="Deselect All";
                  document.getElementById('btnSelAll_Bot').value ="Deselect All";
             }
             else
             {
                  document.getElementById('btnSelAll_Top').value ="Select All";
                  document.getElementById('btnSelAll_Bot').value ="Select All";
             }
             return false;
     }
</script>

Function to Get GridView Row And Column through JavaScript

<script language="javascript" type="text/javascript">
var gridViewCtlId = '<%=ctlGridView.ClientID%>';
    var gridViewCtl = null;
    var curSelRow = null;
    var curRowIdx = -1;
    function getGridViewControl()
    {
        if (null == gridViewCtl)
        {
            gridViewCtl = document.getElementById(gridViewCtlId);
        }
    }
    
    function onGridViewRowSelected(rowIdx)
    {
        var selRow = getSelectedRow(rowIdx);
        if (null != selRow)
        {
            curSelRow = selRow;
            var cellValue = getCellValue(rowIdx, 0);
            alert(cellValue);
        }
    }
    
    function getSelectedRow(rowIdx)
    {
        return getGridRow(rowIdx);
    }
    
    function getGridRow(rowIdx)
    {
        getGridViewControl();
        if (null != gridViewCtl)
        {
            return gridViewCtl.rows[rowIdx];
        }
        return null;
    }
    
    function getGridColumn(rowIdx, colIdx)
    {
        var gridRow = getGridRow(rowIdx);
        if (null != gridRow)
        {
            return gridRow.cells[colIdx];
        }
        return null;
    }
    
    function getCellValue(rowIdx, colIdx)
    {
        var gridCell = getGridColumn(rowIdx, colIdx);
        if (null != gridCell)
        {
            return gridCell.innerText;
        }
        return null;
    }
</script>
  

Wednesday, June 23, 2010

Rename Table's Column Name in Oracle

SQL> desc phone;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PHONE_ID                                  NOT NULL NUMBER(10)
 FK_PHONE_ACCOUNT_ID                       NOT NULL NUMBER(10)
 PHONE_AREACODE                            NOT NULL VARCHAR2(5)
 PHONE_NUMBER                              NOT NULL NUMBER(10)
 PHONE_CITY                                NOT NULL VARCHAR2(40)
 FK_PHONE_PLAN_ID                          NOT NULL NUMBER(5)
 FK_PHONE_USAGE_ID                         NOT NULL NUMBER(5)
 PHONE_ENABLED                             NOT NULL NUMBER(1)
 FK_EMPLOYEEID                             NOT NULL NUMBER(10)
 COMPANY_AMOUNT                                     NUMBER(10,2)


SQL> alter table phone rename column PHONE_CITY to FK_IIL_COMP_LOC_ID;
SQL> Desc Phone;

 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PHONE_ID                                  NOT NULL NUMBER(10)
 FK_PHONE_ACCOUNT_ID                       NOT NULL NUMBER(10)
 PHONE_AREACODE                            NOT NULL VARCHAR2(5)
 PHONE_NUMBER                              NOT NULL NUMBER(10)
 FK_IIL_COMP_LOC_ID                        NOT NULL VARCHAR2(40)
 FK_PHONE_PLAN_ID                          NOT NULL NUMBER(5)
 FK_PHONE_USAGE_ID                         NOT NULL NUMBER(5)
 PHONE_ENABLED                             NOT NULL NUMBER(1)
 FK_EMPLOYEEID                             NOT NULL NUMBER(10)
 COMPANY_AMOUNT                                     NUMBER(10,2)

Monday, June 14, 2010

Example for Allowing Only Numric in a textbox on Client side

<asp:TextBox ID="txt_tenderno"  onkeydown="return onKeyPressBlockNumbers(event)" onFocus="this.style.background ='yellow'" onBlur="this.style.background='white'" runat="server" ></asp:TextBox>
function onKeyPressBlockNumbers(e)
{
 var key = window.event ? e.keyCode : e.which;
 var keychar = String.fromCharCode(key);
 reg = /\d/;
 return !reg.test(keychar);
}
-----------------OR---------------------
<asp:TextBox ID="txt_tenderno"  onkeydown="return numeric(event)" onFocus="this.style.background ='yellow'" onBlur="this.style.background='white'" runat="server" ></asp:TextBox>
function numeric(e) {
var key = window.event ? e.keyCode : e.which;
   return ((key == 8) || (key > 47 && key < 58));
}


 

To get Grid View Rows in Javascript

<script language="javascript" type="text/javascript">
var gridViewCtlId = '<%=ctlGridView.ClientID%>';
    var gridViewCtl = null;
    var curSelRow = null;
    var curRowIdx = -1;
    function getGridViewControl()
    {
        if (null == gridViewCtl)
        {
            gridViewCtl = document.getElementById(gridViewCtlId);
        }
    }
    
    function onGridViewRowSelected(rowIdx)
    {
        var selRow = getSelectedRow(rowIdx);
        if (null != selRow)
        {
            curSelRow = selRow;
            var cellValue = getCellValue(rowIdx, 0);
            alert(cellValue);
        }
    }
    
    function getSelectedRow(rowIdx)
    {
        return getGridRow(rowIdx);
    }
    
    function getGridRow(rowIdx)
    {
        getGridViewControl();
        if (null != gridViewCtl)
        {
            return gridViewCtl.rows[rowIdx];
        }
        return null;
    }
    
    function getGridColumn(rowIdx, colIdx)
    {
        var gridRow = getGridRow(rowIdx);
        if (null != gridRow)
        {
            return gridRow.cells[colIdx];
        }
        return null;
    }
    
    function getCellValue(rowIdx, colIdx)
    {
        var gridCell = getGridColumn(rowIdx, colIdx);
        if (null != gridCell)
        {
            return gridCell.innerText;
        }
        return null;
    }
</script>

Thursday, June 10, 2010

Change Default Formate in Oracle

ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY';

Tuesday, June 8, 2010

ClickOnce Deployment In Visula Basic 2008 Express Edition

I see. well yes you can do this, its called ClickOnce deployment. Take a look at this:


if you have the full version of VS.NET, then you could make your own installer and has more flexibility on what you can do but since its the express version, you get ClickOnce deployment

Monday, June 7, 2010

Listing Files in Dictionary

 Private Sub ListFilesInDictionay(ByVal sStartDir As String, ByRef MyDict As Dictionary(Of Integer, String))
        Dim OutDir As DirectoryInfo = New DirectoryInfo(sStartDir)
        If OutDir.Exists Then
            Dim MyFileNum As Integer = 1
            For Each OurFile As FileInfo In OutDir.GetFiles
                MyDict.Add(MyFileNum, OurFile.Name)
                MyFileNum += 1
            Next
        End If
    End Sub

Tuesday, June 1, 2010

To Show Controls those are not validated as yellow background

on the page_prerender event paste below scratched code

foreach (BaseValidator valControl in Page.Validators)
{
WebControl assControl = (WebControl)Page.FindControl(valControl.ControlToValidate);
if (!valControl.IsValid)
assControl.BackColor = System.Drawing.Color.Yellow;
else
assControl.BackColor = System.Drawing.Color.White;
}
}