Advertisement

06.28.2008 at 01:19AM PDT, ID: 23523660
[x]
Attachment Details

unable to check the top checkbox in dataGrid

Asked by bdpsg in JavaScript, VB Database Programming, Programming for ASP.NET

Tags: ,

hi, i have created a checkbox column in the dataGrid. however, i keep encounter the problem of not able to check the top checkbox when selecting the top checkbox to checkall. eg. all other checkboxes are checked except the top one.
can anyone help me to solve this problem?

<script language =javascript >
   
    var blnIsChk = new Boolean(false);
   
    </script>


   
    <script language =javascript for ="chkAll" event="onclick">
   
     window.event.returnValue=false;
    var objElement = new Object();
    var aryElements = new Array();
    var intIndex = new Number(0);
    var intMaxIndex = new Number(0);
   
    aryElements = window.document .getElementsByTagName ("input");
    intMaxIndex= aryElements.length - 1;
   
    for(intIndex=0; intIndex<=intMaxIndex ; intIndex++){
        objElement = aryElements[intIndex];
        if(objElement.id="chkAdministratorId"){
            if(blnIsChk == false){
                objElement.checked = true;
             }else{
                objElement.checked = false;
                }
           
        }//if
    }//for
   
    if(blnIsChk == true){
        blnIsChk = false;
    }else{
        blnIsChk = true;
    }
   
    </script>
   
   
</head>
<body>
    <form id="frmData" runat="server">
    <div>
   
    <table border ="1" width =600>
    <tr>
        <td bgcolor =pink >
        <asp:Label ID="lblMessage" runat =server Text =""></asp:Label>
        </td>
    </tr>
    <tr>
        <td colspan ="2" align= right bgcolor="#ff9999" bordercolor =red >
        <asp:Button ID ="btnAdd" runat =server Text ="Add Administrator" />
        <asp:Button ID="btnDelete" runat =server Text ="Delete" />
       
    </tr>
   
    <tr >
        <td align =center bgcolor ="#ff9999" bordercolor =red  >
        <asp:DataGrid ID="grdData" runat =server AutoGenerateColumns =false AllowPaging =true PageSize ="5">
            <PagerStyle Mode ="NumericPages" HorizontalAlign =Right  />
            <Columns>
            <asp:BoundColumn DataField ="AdministratorId" Visible =false ></asp:BoundColumn>
            <asp:BoundColumn HeaderStyle-BackColor =Lavender ></asp:BoundColumn>
            <asp:BoundColumn DataField ="UserId" Visible =true HeaderText ="User Id" HeaderStyle-BackColor =Lavender ></asp:BoundColumn>
            <asp:BoundColumn DataField ="FullName" Visible =true HeaderText ="Full Name" HeaderStyle-BackColor =Lavender  ></asp:BoundColumn>
            <asp:ButtonColumn ButtonType="PushButton" Text="Edit" HeaderStyle-BackColor =Lavender  />
           
            </Columns>
        </asp:DataGrid>
        <br />
        </td>
    </tr>
   
    </table>
    </div>
    </form>
</body>

=====================================================
below is the behind code to create the checkboxes in the datagrid:

Protected Sub grdData_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdData.ItemDataBound
        If e.Item.ItemType <> ListItemType.Header And _
            e.Item.ItemType <> ListItemType.Footer Then
            e.Item.Cells(1).Text = "<input type=""checkbox""value=""" & _
            e.Item.Cells(0).Text & """name=""chkAdministratorId"" id=""chkAdministratorId"">"
        End If

        If e.Item.ItemType = ListItemType.Header Then
            e.Item.Cells(1).Text = "<input type=""checkbox""value=""" & _
            e.Item.Cells(0).Text & """name=""chkAll"" id=""chkAll"">"
        End If
    End Sub

Start Free Trial
 
Loading Advertisement...
 
[+][-]06.28.2008 at 06:55AM PDT, ID: 21890922

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 07:28AM PDT, ID: 21891007

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 07:44AM PDT, ID: 21891060

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 07:47AM PDT, ID: 21891064

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 07:50AM PDT, ID: 21891076

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, VB Database Programming, Programming for ASP.NET
Tags: vb, javascript, ie
Sign Up Now!
Solution Provided By: hielo
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.28.2008 at 08:06AM PDT, ID: 21891122

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 08:25AM PDT, ID: 21891163

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 09:15AM PDT, ID: 21891295

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 09:53AM PDT, ID: 21891388

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 10:06AM PDT, ID: 21891418

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628