Thursday, 9 May 2013

Select gridview row using Javascript



I want to select particular row of gridview with using UpdatePanel or postback

For that I prefer javascript ,

Javascript Code :

     <script type="text/javascript">

      /*Script For Highlighting particlar row */

        function HighlightRow(chkB) {
            var IsChecked = chkB.checked;
            if (IsChecked) {
                chkB.parentElement.parentElement.style.backgroundColor = '#F5D0A9';
                chkB.parentElement.parentElement.style.color = 'white';
                // chkB.parentElement.cell[7].disabled = true;
                //  document.getElementbyID('ddlGridSubDepartment').disabled = '';
                chkB.removeattr

            } else {
                chkB.parentElement.parentElement.style.backgroundColor = 'white';
                chkB.parentElement.parentElement.style.color = 'black';
            }
        }


    /*Script For selecting all rows */

    function selectAll(invoker) {
            // Since ASP.NET checkboxes are really HTML input elements
            //  let's get all the inputs            
             var inputElements = document.getElementsByTagName('input');
            for (var i = 0; i < inputElements.length; i++) {
                var myElement = inputElements[i];
                // Filter through the input types looking for checkboxes
                if (myElement.type === "checkbox") {
                    // Use the invoker (our calling element) as the reference
                    //  for our checkbox status
                    myElement.checked = invoker.checked;
                }
            }
        } 

</script>


<asp:GridView ID="gvMasterRecord" ..... >

 <Columns>
                                              
 <asp:TemplateField HeaderText="chk">
        <ItemTemplate>
               <asp:CheckBox ID="chkRecord" runat="server" AutoPostBack="true" onClick="javascript:HighlightRow(this);" OnCheckedChanged="chkRecord_CheckedChanged" />
       </ItemTemplate>
        <HeaderTemplate>
                <asp:CheckBox ID="chkRecord" runat="server" OnClick="selectAll(this)" />
       </HeaderTemplate>
</asp:TemplateField>
</columns>

</asp:GridView>





No comments:

Post a Comment