troubleshooting Question

How to select a CheckBox in a GridView EditItemTemplate with a DropDownList OnChange event in same EditItemTemplate

Avatar of megnin
megninFlag for United States of America asked on
JavaScriptASP.NET
11 Comments1 Solution1467 ViewsLast Modified:
In my GridView in Edit mode I've put a CheckBox in one field and a DropDownList in another field.

I need the CheckBox to be checked when the DropDownList is changed.

I thought I had accomplished this with the Onchange in the DropDownList below, but on looking in the source view when it didn't work (except on the top record) I noticed that the CheckBox that I'm trying to check is numbered according to what row it's on.
'GridView1_SeeSuccessCoach_0' only applies to the first row.
The CheckBox on the second row is 'GridView1_SeeSuccessCoach_1', etc.

How can I check the CB on whatever row is being edited?  The DropDownList OnChange of that row should be the trigger.  Thanks.

<asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Prog" SortExpression="CaseManager">
			<EditItemTemplate>
				<%--<asp:TextBox ID="txtCaseManager" runat="server" Text='<%# Bind("CaseManager") %>'></asp:TextBox>--%>

    <asp:DropDownList ID="ddlCaseManager" runat="server" Text='<%# Bind("CaseManager") %>' AppendDataBoundItems="true"
        Onchange="document.getElementById('GridView1_SeeSuccessCoach_0').checked = Boolean(this.selectedIndex);" >
        <asp:ListItem Value="" Text="n/a"/>
        <asp:ListItem Value="AARP" Text="AARP" />
        <asp:ListItem Value="BDS" Text="BDS" />
        <asp:ListItem Value="EUC-RES" Text="EUC-RES" />
        <asp:ListItem Value="Gulf Coast" Text="Gulf Coast" />
        <asp:ListItem Value="OIC" Text="OIC" />
        <asp:ListItem Value="REA" Text="REA" />
        <asp:ListItem Value="SNAP" Text="SNAP" />
        <asp:ListItem Value="TAA" Text="TAA" />
        <asp:ListItem Value="TTW" Text="TTW" />
        <asp:ListItem Value="Vet" Text="Veteran" />
        <asp:ListItem Value="WIA" Text="WIA" />
        <asp:ListItem Value="WP" Text="WP" />
        <asp:ListItem Value="DHM" Text="DHM-T" />
        <asp:ListItem Value="WTP" Text="WTP" />
        <asp:ListItem Value="Youth" Text="Youth" />
        <asp:ListItem Value=" " Text=""/>
    </asp:DropDownList>

			</EditItemTemplate>
			<ItemTemplate>
				<asp:Label ID="lblCaseManager" runat="server" Text='<%# Eval("CaseManager") %>'></asp:Label>
			</ItemTemplate>
			<ControlStyle Width="100px" />
			<HeaderStyle BackColor="#0033EE" Font-Size="Smaller" />
			<ItemStyle Font-Size="Smaller" HorizontalAlign="Center" />
</asp:TemplateField>
ASKER CERTIFIED SOLUTION
Rouchie

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros