locked
when change drop-down checkbox does't checked RRS feed

  • Question

  • User-582711651 posted

    Hi Friends, 

    My jquery is partially is working, the condition is when the user changes the dropdown items if the row item value is 5  then checkbox should be checked, else checkbox should be unchecked.

    This is my asp grid,

    <asp:GridView ID="Grv_NOTR_List" runat="server" AutoGenerateColumns="False" CssClass="normalText2" OnRowDataBound="OnRowDataBound_NOTR" >
    <AlternatingRowStyle Wrap="False" />
    <Columns>
    <asp:TemplateField HeaderText="-">
    <HeaderTemplate>
    <asp:CheckBox ID="ChkBox_Header" runat="server" CssClass="smalltext2" Checked="true" onclick="SelectAll(this)" />
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="ChkBox" runat="server" CssClass="smalltext2" Checked="true" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Sr#">
    <ItemTemplate>
    <%#Container.DataItemIndex + 1 %>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="IDT" HeaderText="." ItemStyle-CssClass="hidecol" 
    HeaderStyle-CssClass="hidecol" >
    <HeaderStyle CssClass="hidecol" />
    <ItemStyle CssClass="hidecol" />
    </asp:BoundField>
    <asp:BoundField DataField="Region" HeaderText="Region" />
    <asp:BoundField DataField="Branch" HeaderText="Branch Name" />
    <asp:BoundField DataField="Cluster" HeaderText="Cluster" />
    <asp:BoundField DataField="Group" HeaderText="Group" />
    <asp:BoundField DataField="LID" HeaderText="Loan#" />
    <asp:BoundField HeaderText="Member " DataField="Member" />
    <asp:BoundField DataField="Demand" HeaderText="Dmd" />
    <asp:BoundField DataField="PAR" HeaderText="PAR" />
    <asp:BoundField DataField="DmdDt" HeaderText="Dmd-Dt" />
    <asp:BoundField DataField="LAmount" HeaderText="Loan" />
    <asp:TemplateField HeaderText="Dispositions">
    <ItemTemplate>
    <asp:DropDownList ID="Drd_Dispo" runat="server" CssClass="normalText2" Width="110px">
    <asp:ListItem Value="0">Select One</asp:ListItem>
    <asp:ListItem Value="1">Member Migration</asp:ListItem>
    <asp:ListItem Value="2">No Info.from Member</asp:ListItem>
    <asp:ListItem Value="3">Member Abscond</asp:ListItem>
    <asp:ListItem Value="4">Ring Leader Iss.</asp:ListItem>
    <asp:ListItem Value="5">Due Paid</asp:ListItem>
    <asp:ListItem Value="6">No followups</asp:ListItem>
    <asp:ListItem Value="7">Mem.Comit to Pay</asp:ListItem>
    </asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="DC">
    <ItemTemplate>
    <asp:CheckBox ID="Chk_DueCloser" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="PTP">
    <ItemTemplate>
    <table class="style28">
    <tr>
    <td class="style32">
    <asp:TextBox ID="Txt_PTP" runat="server" cssclass="normalText2"  Width="70px" 
    ></asp:TextBox> 
    <cc1:CalendarExtender ID="CExdr_PTP_Dt" runat="server" Format="dd/MM/yyyy" PopupButtonID="Img_PTP" OnClientDateSelectionChanged="checkDate" 
    TargetControlID="Txt_PTP" >
    </cc1:CalendarExtender>
    <cc1:MaskedEditExtender ID="MskEditExtd_PTP" runat="server" Mask="99/99/9999" MaskType="Date"
    PromptCharacter=" " TargetControlID="Txt_PTP" UserDateFormat="DayMonthYear">
    </cc1:MaskedEditExtender>
    </td>
    <td>
    <asp:Image ID="Img_PTP" runat="server" Height="17px" ImageUrl="~/Images/Ico_Dt.gif" Width="21px" />
    </td>
    <td>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="FLG" HeaderText="." ItemStyle-CssClass="hidecol" 
    HeaderStyle-CssClass="hidecol" >
    <HeaderStyle CssClass="hidecol" />
    <ItemStyle CssClass="hidecol" />
    </asp:BoundField>
    <asp:BoundField DataField="DISPID" HeaderText="." ItemStyle-CssClass="hidecol" 
    HeaderStyle-CssClass="hidecol" >
    <HeaderStyle CssClass="hidecol" />
    <ItemStyle CssClass="hidecol" />
    </asp:BoundField>
    <asp:BoundField DataField="PTPDt" HeaderText="." ItemStyle-CssClass="hidecol" 
    HeaderStyle-CssClass="hidecol" >
    <HeaderStyle CssClass="hidecol" />
    <ItemStyle CssClass="hidecol" />
    </asp:BoundField>
    <asp:TemplateField HeaderText="@">
    <ItemTemplate>
    <asp:ImageButton ID="Img_btn_Info" runat="server" Height="20px" 
    ImageUrl="~/Images/UserConsole_ICO/Info_48png.png" Width="20px" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    <EditRowStyle Wrap="False" />
    <FooterStyle 
    Wrap="False" />
    <HeaderStyle 
    Wrap="False" />
    <PagerStyle 
    Wrap="False" />
    <RowStyle Wrap="False" />
    <SelectedRowStyle Wrap="False" />
    </asp:GridView>

    This is my jquery script

    <script src="JScript/jquery-1.5.2.js" type="text/javascript"></script>
    <script type="text/javascript">
    
            $("[id*=Drd_Dispo]").live("change", function () {
                if ($(this).val() === "5") {
                    
                    var drd_stat = $(this).closest('tr').find("[id*=Chk_DueCloser]").attr('checked') ? true : false;
                    alert(drd_stat); // Upto here working, Im getting status
    
                  	$(this).closest().find("[id*=Chk_DueCloser]").prop('checked', true);
                } else {
                    $(this).closest().find("[id*=Chk_DueCloser]").prop('checked', false);
                }
            });
    </script>

    How I do this, pls help me

    Thanks in advance. 

    Sunday, November 3, 2019 5:29 PM

Answers

  • User283571144 posted

    Hi ayyappan.CNN,

    According to your description, I suggest you could try to use $("select[id*=Drd_Dispo]")'s on change function to achieve your requirement.

    More details, you could refer to below codes:

    <script type="text/javascript">
            $(document).ready(function () {  
              
     $("select[id*=Drd_Dispo]").on("change", function () {
                    if ($(this).val() === "5") {
                        //var drd_stat = $(this).find("[id*=Chk_DueCloser]").prop('checked') ? true : false;
                        //alert(drd_stat); // Upto here working, Im getting status
                       $(this).parent().next().find("input[id*=Chk_DueCloser]").attr("checked", "checked");
                    } else {
                        $(this).closest().find("[id*=Chk_DueCloser]").prop('checked', true);
                    }
                }); 
    
            });
           
    </script> 
    
     <div>
                <asp:GridView ID="Grv_NOTR_List" runat="server" AutoGenerateColumns="False" CssClass="normalText2"  >
                    <AlternatingRowStyle Wrap="False" />
                    <Columns>
                        <asp:TemplateField HeaderText="-">
                            <HeaderTemplate>
                                <asp:CheckBox ID="ChkBox_Header" runat="server" CssClass="smalltext2" Checked="true" onclick="SelectAll(this)" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="ChkBox" runat="server" CssClass="smalltext2" Checked="true" />
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Sr#">
                            <ItemTemplate>
                                <%#Container.DataItemIndex + 1 %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <%--<asp:BoundField DataField="IDT" HeaderText="." ItemStyle-CssClass="hidecol"  HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>--%>
                        <asp:BoundField DataField="Region" HeaderText="Region" />
                        <asp:BoundField DataField="Branch" HeaderText="Branch Name" />
                        <asp:BoundField DataField="Cluster" HeaderText="Cluster" />
                        <asp:BoundField DataField="Group" HeaderText="Group" />
                        <asp:BoundField DataField="LID" HeaderText="Loan#" />
                        <asp:BoundField HeaderText="Member " DataField="Member" />
                        <asp:BoundField DataField="Demand" HeaderText="Dmd" />
                        <asp:BoundField DataField="PAR" HeaderText="PAR" />
                        <asp:BoundField DataField="DmdDt" HeaderText="Dmd-Dt" />
                        <asp:BoundField DataField="LAmount" HeaderText="Loan" />
    
                        <asp:TemplateField HeaderText="Dispositions">
                            <ItemTemplate>
                                <asp:DropDownList ID="Drd_Dispo" runat="server" CssClass="normalText2" Width="110px">
                                    <asp:ListItem Value="0">Select One</asp:ListItem>
                                    <asp:ListItem Value="1">Member Migration</asp:ListItem>
                                    <asp:ListItem Value="2">No Info.from Member</asp:ListItem>
                                    <asp:ListItem Value="3">Member Abscond</asp:ListItem>
                                    <asp:ListItem Value="4">Ring Leader Iss.</asp:ListItem>
                                    <asp:ListItem Value="5">Due Paid</asp:ListItem>
                                    <asp:ListItem Value="6">No followups</asp:ListItem>
                                    <asp:ListItem Value="7">Mem.Comit to Pay</asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="DC">
                            <ItemTemplate>
                                <asp:CheckBox ID="Chk_DueCloser" runat="server" Checked="false" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="PTP">
                            <ItemTemplate>
                                <table class="style28">
                                    <tr>
                                        <td class="style32">
                                            <asp:TextBox ID="Txt_PTP" runat="server" cssclass="normalText2"  Width="70px" ></asp:TextBox>
                                         
    <%--                                        <cc1:CalendarExtender ID="CExdr_PTP_Dt" runat="server" Format="dd/MM/yyyy" PopupButtonID="Img_PTP" OnClientDateSelectionChanged="checkDate" TargetControlID="Txt_PTP" ></cc1:CalendarExtender>
                                            <cc1:MaskedEditExtender ID="MskEditExtd_PTP" runat="server" Mask="99/99/9999" MaskType="Date" ter=" " TargetControlID="Txt_PTP" UserDateFormat="DayMonthYear"></cc1:MaskedEditExtender>--%>
                                        </td>
                                        <td>
                                            <asp:Image ID="Img_PTP" runat="server" Height="17px" ImageUrl="~/image/Jong Suk li.jpg" Width="21px" />
                                        </td>
                                        <td>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:TemplateField>
                       <%-- <asp:BoundField DataField="FLG" HeaderText="." ItemStyle-CssClass="hidecol" HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>--%>
                       <%-- <asp:BoundField DataField="DISPID" HeaderText="." ItemStyle-CssClass="hidecol"  HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>
                        <asp:BoundField DataField="PTPDt" HeaderText="." ItemStyle-CssClass="hidecol"  HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="@">
                            <ItemTemplate>
                                <asp:ImageButton ID="Img_btn_Info" runat="server" Height="20px"
                                    ImageUrl="~/Images/UserConsole_ICO/Info_48png.png" Width="20px" />
                            </ItemTemplate>
                        </asp:TemplateField>--%>
                    </Columns>
                    <EditRowStyle Wrap="False" />
                    <FooterStyle Wrap="False" />
                    <HeaderStyle Wrap="False" />
                    <PagerStyle Wrap="False" />
                    <RowStyle Wrap="False" />
                    <SelectedRowStyle Wrap="False" />
                </asp:GridView>
            </div>
    

    Code-behind:

    protected void bind()
            {
                string str, strSql;
                str = System.Configuration.ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542ConnectionString"].ConnectionString;
                SqlConnection conn = new SqlConnection(str);
                strSql = "select * from demo";
                SqlDataAdapter da = new SqlDataAdapter(strSql, str);
                DataSet ds = new DataSet();
                da.Fill(ds, "demo");
                Grv_NOTR_List.DataSource = ds.Tables[0].DefaultView;
                Grv_NOTR_List.DataBind();
                conn.Close();
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    bind();
                }
            }
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 4, 2019 7:16 AM

All replies

  • User283571144 posted

    Hi ayyappan.CNN,

    According to your description, I suggest you could try to use $("select[id*=Drd_Dispo]")'s on change function to achieve your requirement.

    More details, you could refer to below codes:

    <script type="text/javascript">
            $(document).ready(function () {  
              
     $("select[id*=Drd_Dispo]").on("change", function () {
                    if ($(this).val() === "5") {
                        //var drd_stat = $(this).find("[id*=Chk_DueCloser]").prop('checked') ? true : false;
                        //alert(drd_stat); // Upto here working, Im getting status
                       $(this).parent().next().find("input[id*=Chk_DueCloser]").attr("checked", "checked");
                    } else {
                        $(this).closest().find("[id*=Chk_DueCloser]").prop('checked', true);
                    }
                }); 
    
            });
           
    </script> 
    
     <div>
                <asp:GridView ID="Grv_NOTR_List" runat="server" AutoGenerateColumns="False" CssClass="normalText2"  >
                    <AlternatingRowStyle Wrap="False" />
                    <Columns>
                        <asp:TemplateField HeaderText="-">
                            <HeaderTemplate>
                                <asp:CheckBox ID="ChkBox_Header" runat="server" CssClass="smalltext2" Checked="true" onclick="SelectAll(this)" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="ChkBox" runat="server" CssClass="smalltext2" Checked="true" />
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Sr#">
                            <ItemTemplate>
                                <%#Container.DataItemIndex + 1 %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <%--<asp:BoundField DataField="IDT" HeaderText="." ItemStyle-CssClass="hidecol"  HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>--%>
                        <asp:BoundField DataField="Region" HeaderText="Region" />
                        <asp:BoundField DataField="Branch" HeaderText="Branch Name" />
                        <asp:BoundField DataField="Cluster" HeaderText="Cluster" />
                        <asp:BoundField DataField="Group" HeaderText="Group" />
                        <asp:BoundField DataField="LID" HeaderText="Loan#" />
                        <asp:BoundField HeaderText="Member " DataField="Member" />
                        <asp:BoundField DataField="Demand" HeaderText="Dmd" />
                        <asp:BoundField DataField="PAR" HeaderText="PAR" />
                        <asp:BoundField DataField="DmdDt" HeaderText="Dmd-Dt" />
                        <asp:BoundField DataField="LAmount" HeaderText="Loan" />
    
                        <asp:TemplateField HeaderText="Dispositions">
                            <ItemTemplate>
                                <asp:DropDownList ID="Drd_Dispo" runat="server" CssClass="normalText2" Width="110px">
                                    <asp:ListItem Value="0">Select One</asp:ListItem>
                                    <asp:ListItem Value="1">Member Migration</asp:ListItem>
                                    <asp:ListItem Value="2">No Info.from Member</asp:ListItem>
                                    <asp:ListItem Value="3">Member Abscond</asp:ListItem>
                                    <asp:ListItem Value="4">Ring Leader Iss.</asp:ListItem>
                                    <asp:ListItem Value="5">Due Paid</asp:ListItem>
                                    <asp:ListItem Value="6">No followups</asp:ListItem>
                                    <asp:ListItem Value="7">Mem.Comit to Pay</asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="DC">
                            <ItemTemplate>
                                <asp:CheckBox ID="Chk_DueCloser" runat="server" Checked="false" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="PTP">
                            <ItemTemplate>
                                <table class="style28">
                                    <tr>
                                        <td class="style32">
                                            <asp:TextBox ID="Txt_PTP" runat="server" cssclass="normalText2"  Width="70px" ></asp:TextBox>
                                         
    <%--                                        <cc1:CalendarExtender ID="CExdr_PTP_Dt" runat="server" Format="dd/MM/yyyy" PopupButtonID="Img_PTP" OnClientDateSelectionChanged="checkDate" TargetControlID="Txt_PTP" ></cc1:CalendarExtender>
                                            <cc1:MaskedEditExtender ID="MskEditExtd_PTP" runat="server" Mask="99/99/9999" MaskType="Date" ter=" " TargetControlID="Txt_PTP" UserDateFormat="DayMonthYear"></cc1:MaskedEditExtender>--%>
                                        </td>
                                        <td>
                                            <asp:Image ID="Img_PTP" runat="server" Height="17px" ImageUrl="~/image/Jong Suk li.jpg" Width="21px" />
                                        </td>
                                        <td>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:TemplateField>
                       <%-- <asp:BoundField DataField="FLG" HeaderText="." ItemStyle-CssClass="hidecol" HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>--%>
                       <%-- <asp:BoundField DataField="DISPID" HeaderText="." ItemStyle-CssClass="hidecol"  HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>
                        <asp:BoundField DataField="PTPDt" HeaderText="." ItemStyle-CssClass="hidecol"  HeaderStyle-CssClass="hidecol" >
                            <HeaderStyle CssClass="hidecol" />
                            <ItemStyle CssClass="hidecol" />
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="@">
                            <ItemTemplate>
                                <asp:ImageButton ID="Img_btn_Info" runat="server" Height="20px"
                                    ImageUrl="~/Images/UserConsole_ICO/Info_48png.png" Width="20px" />
                            </ItemTemplate>
                        </asp:TemplateField>--%>
                    </Columns>
                    <EditRowStyle Wrap="False" />
                    <FooterStyle Wrap="False" />
                    <HeaderStyle Wrap="False" />
                    <PagerStyle Wrap="False" />
                    <RowStyle Wrap="False" />
                    <SelectedRowStyle Wrap="False" />
                </asp:GridView>
            </div>
    

    Code-behind:

    protected void bind()
            {
                string str, strSql;
                str = System.Configuration.ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542ConnectionString"].ConnectionString;
                SqlConnection conn = new SqlConnection(str);
                strSql = "select * from demo";
                SqlDataAdapter da = new SqlDataAdapter(strSql, str);
                DataSet ds = new DataSet();
                da.Fill(ds, "demo");
                Grv_NOTR_List.DataSource = ds.Tables[0].DefaultView;
                Grv_NOTR_List.DataBind();
                conn.Close();
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    bind();
                }
            }
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 4, 2019 7:16 AM
  • User-582711651 posted

    Dear Brando ZWZ, 

    Great! thanks a lot. I have added a blow line for uncheck it works well. 

     $(this).parent().next().find("input[id*=Chk_DueCloser]").attr('checked', false);

    Thanks

    Monday, November 4, 2019 4:14 PM