Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2007, 04:26 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Finding Controls and Checking Boxes

Hi All,

I'm generating a folder tree with the following repeater. It creates a parent using the database values, AreaID for the parent and SubID for child objects, hiding and unhiding a div layer to show the child objects with a javascript function that works fine.

What I'm trying to do and am having trouble with is that I want to be able to check the check box for the parent, have all the child check boxes checked = True and vice versa when unchecking the parent have all the child checkboxes.checked = False.

Code:
<asp:Repeater ID="rptAreas" Runat="server">
    <HeaderTemplate>
        <table border="0" cellpadding="0" cellspacing="0">
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td valign="top">
                <img border="0" src="/images/icons/spacer.gif" width="16" height="2" /><br />
                <img border="0" src="/images/icons/max_sm.gif" width="16" height="16" align="absmiddle" name="_Area<%#DataBinder.Eval(Container.DataItem, "AreaID")%>" alt="Maximize" onclick="javascript:showHide('Area<%#DataBinder.Eval(Container.DataItem, "AreaID")%>');" /><br />
            </td>
            <td>
                <asp:CheckBox ID="chkAreaID" AutoPostBack="True" OnCheckedChanged="chkAreaID_CheckedChanged" Runat="server" />
                <b><%#DataBinder.Eval(Container.DataItem, "AreaName")%></b><br />
                <div id="Area<%#DataBinder.Eval(Container.DataItem, "AreaID")%>" class="hide">
                    <asp:CheckBoxList ID="cblSubID" CellPadding="0" CellSpacing="0" Runat="server" />
                </div>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
I can see in the source of the web page that there are ID's generated:

<input id="rptAreas__ctl9_chkAreaID" type="checkbox" name="rptAreas:_ctl9:chkAreaID" onclick="__doPostBack('rptAreas$_ctl9$chkAreaID',' ')" language="javascript" />
<input id="rptAreas__ctl9_cblSubID_0" type="checkbox" name="rptAreas:_ctl9:cblSubID:0" checked="checked" />

So I'm thinking there might be a way to access those ctl numbers and whether or not say for the above examples I'd be looking INSTR for the ID 'ctl9' and all of the SubID's generated for that parent.

I don't even know if I'm going about this in the right way. Please, any suggestions would be greatly appreciated. And even if I am going in the right direction how to access those names or ID's.

Thank you,
Richard


 
Old October 30th, 2007, 02:01 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

OK. I think I got it. This code is used to assign permit numbers but only one permit number can be assigned to a Subarea (SubID) so that's the reason for the 'If' inside the loop. If the check box has been disabled then checking or unchecking the parent won't do anything.

    Protected Sub chkAreaID_CheckedChanged(ByVal s As Object, ByVal e As EventArgs)
        Try
            Dim cblSubID As CheckBoxList = s.Parent.FindControl("cblSubID")
            For Each Item As ListItem In cblSubID.Items
                If cblSubID.Items.IsReadOnly = False Then
                    Item.Selected = s.Checked
                End If
            Next
        Catch ex As Exception
            Session("Alert") = ex.Message
        End Try
    End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for controls existence .NET 2.0 sarosh General .NET 0 March 1st, 2006 02:30 AM
Finding child controls Hunter ASP.NET 1.0 and 1.1 Professional 4 October 27th, 2005 09:09 AM
Finding Dynamic controls mpdillon General .NET 0 March 30th, 2005 01:31 PM
checking boxes dazednconfused Beginning PHP 1 July 16th, 2003 09:52 AM
SQL , List Boxes/Menu Boxes, DB's Ginzu3 Classic ASP Databases 1 June 30th, 2003 04:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.