troubleshooting Question

vb.net Passing GridView Row # to a javascript function

Avatar of Robert Hamel
Robert HamelFlag for United States of America asked on
JavaScriptASP.NETVisual Basic.NET
6 Comments1 Solution682 ViewsLast Modified:
Hi, I have a gridview, where each gridview has a checkbox in column 1, and form fields in column 2 and 3.  My desired effect is that if the checkbox status changes, i want to either hide or unhide the form fields in the same row.
I have this workign with a check all button and uncheck all button, but when trying to create an OnCheckChanged event for the individual row, i'm not sure how to pass in the row number so I can identify the fields to make hidden.

In the code Below, i'd like go pass in "ROWNUMBER" variable to my function, so then I could use in my javascript

var thisField = document.getElementById('StudentGrid_TextBoxNextRequiredDate_' + ROWNUMBER);
          var thisWarningField = document.getElementById('StudentGrid_TextBoxWarningDays_' + ROWNUMBER);
          var thisCheckField = document.getElementById('StudentGrid_CheckBoxStudentSelect_' + ROWNUMBER);
 if ((thisField.value == "") && (thisCheckField.checked == 1)) {
              thisField.style.visibility = 'visible';
              thisWarningField.style.visibility = 'visible';

              thisField.value = "1/1/2021";
              thisWarningField.value = "30";
          }
          else if ((thisField.value != "") && (thisCheckField.checked == 1)) {
              thisField.style.visibility = 'visible';
              thisWarningField.style.visibility = 'visible';

              //thisField.value = "1/1/2021";
              //thisWarningField.value = "30";
          }

          else if ((thisField.value == "") && (thisCheckField.checked == 0)) {
              //thisField.value = "";
              //thisWarningField.value = "";
              thisField.style.visibility = 'hidden';
              thisWarningField.style.visibility = 'hidden';

          }
          else if ((thisField.value != "") && (thisCheckField.checked == 0)) {
              //thisField.value = "";
              //thisWarningField.value = "";
              thisField.style.visibility = 'hidden';
              thisWarningField.style.visibility = 'hidden';
          }
<asp:GridView runat="server" ID="StudentGrid"  AlternatingRowStyle-CssClass="GridAltRow" RowStyle-CssClass="GridRow" AutoGenerateColumns="False" Width="500">
                       <Columns>
                            
                  <asp:TemplateField HeaderText="">
                  <ItemTemplate>
                    <asp:CheckBox ID="CheckBoxStudentSelect" OnCheckedChanged="hideunhide(this,ROWNUMBER)" runat="server" value='<%# Eval("Student_Number") %>' />
                  </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Student Name" ItemStyle-HorizontalAlign="Left">
                  <ItemTemplate>
                    <asp:Label ID="LabelFirstName" runat="server" Text='<%# Eval("First_Name") & " " & Eval("Last_Name") %>'></asp:Label>
                    <asp:HiddenField ID="HiddenStudentNumber" runat="server" Value='<%# Eval("Student_Number") %>'/>
                  </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Warning Days">
                  <ItemTemplate>
                    <asp:TextBox ID="TextBoxWarningDays" runat="server" Text='<%# Eval("WarningDays")%>' Width="70" ReadOnly="True"></asp:TextBox>
                    <asp:HiddenField ID="HiddenWarningDays" runat="server" Value='<%# Eval("WarningDays")%>' />
                    
                  </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Next Required Date">
                  <ItemTemplate>
                    <asp:TextBox ID="TextBoxNextRequiredDate" runat="server" Text='<%# CheckNullDate(Eval("NextRequiredDate"))%>' Width="70" ReadOnly="True"></asp:TextBox>
                    <asp:HiddenField ID="HiddenNextRequiredDate" runat="server" Value='<%# Eval("NextRequiredDate")%>'/>
                    <ajaxToolkit:CalendarExtender ID="CalExtEnd" runat="server" TargetControlID="TextBoxNextRequiredDate" />
                  </ItemTemplate>
                </asp:TemplateField>
                        </Columns>
                    
                    </asp:GridView>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
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 6 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