Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create a Products page that contain product name, price, quantity.
2) In Gridview, I have Given provision (check box) to select any product.

C#
<asp:GridView ID="gvCheckboxes" runat="server" AutoGenerateColumns="False" 
                        OnRowCreated="gvCheckboxes_RowCreated" 
                        onselectedindexchanged="gvCheckboxes_SelectedIndexChanged" 
                        DataKeyNames="sid">
                        <columns>
                            <asp:TemplateField HeaderText="Select">
                                <itemtemplate>
                                    <asp:CheckBox ID="chkBxSelect" runat="server" />
                                </itemtemplate>
                                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                                <itemstyle horizontalalign="Center" verticalalign="Middle" width="50px" />
                                <HeaderTemplate>
                                    <asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
                                </HeaderTemplate>
                            
                            <asp:BoundField HeaderText="Student Name" DataField="Sname" ReadOnly="True">
                                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                                <itemstyle horizontalalign="Center" verticalalign="Middle" width="50px" />
                            
                            <asp:BoundField DataField="m1" HeaderText="Mark1" ReadOnly="True" />
                            <asp:BoundField DataField="m2" HeaderText="Mark2" ReadOnly="True" />
                            <asp:BoundField DataField="m3" HeaderText="Mark3" ReadOnly="True" />
                            <asp:BoundField DataField="m4" HeaderText="Mark4" ReadOnly="True" />
                            
                        </columns>


C#
<script type="text/javascript">
        var TotalChkBx;
        var Counter;

        window.onload = function () {
            //Get total no. of CheckBoxes in side the GridView.
            TotalChkBx = parseInt('<%= this.gvCheckboxes.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.gvCheckboxes.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>

3)After select the products in GridView,how to show the product name and (price*quantity)as total price and total no of product in another Gridview.

4)I want to show/remove the information in another Gridview when i select/deselect the checkbox in the first Gridview...
Posted
Updated 27-Jun-14 2:46am
v3
Comments
Prasad Avunoori 27-Jun-14 7:58am    
Just pass the ProductIds to the server, build another stored procedure to do the work (price*Quantity) bind it in another Popup's gridview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900