locked
Compare Two Column IF Column1 value is greater then Column2 RRS feed

Answers

  • User288213138 posted

    Hi Gopi.MCA,

    Please describe your requirement in detail as much as possible.

    I made a demo for your reference:

     <script type="text/javascript">
            $(function () {
                $("[id*=Gridview1]").find("[id*=lnkSelect]").click(function () {
                    var row = $(this).closest("tr");
                    var h2 = row.find("td").eq(2).find("input").eq(0).val();
                    var h3 = row.find("td").eq(3).find("input").eq(0).val();
                    if (parseInt(h2) > parseInt(h3))
                    {
                        alert("h2>h3");
                    }
                    if (parseInt(h2) < parseInt(h3)) {
                        alert("h2<h3");
                    }            
                    return false;
                });
            });
    </script>
    
     <asp:GridView ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
    
                    <Columns>
                        <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
                        <asp:TemplateField HeaderText="Header 1">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    
                        <asp:TemplateField HeaderText="Header 2">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    
                        <asp:TemplateField HeaderText="Header 3">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                            </ItemTemplate>
                            <FooterStyle HorizontalAlign="Right" />
                            <FooterTemplate>                          
                                <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click" />
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkSelect" runat="server" Text="Select" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

    The result:

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 24, 2019 7:30 AM

All replies

  • User288213138 posted

    Hi Gopi.MCA,

    Please describe your requirement in detail as much as possible.

    I made a demo for your reference:

     <script type="text/javascript">
            $(function () {
                $("[id*=Gridview1]").find("[id*=lnkSelect]").click(function () {
                    var row = $(this).closest("tr");
                    var h2 = row.find("td").eq(2).find("input").eq(0).val();
                    var h3 = row.find("td").eq(3).find("input").eq(0).val();
                    if (parseInt(h2) > parseInt(h3))
                    {
                        alert("h2>h3");
                    }
                    if (parseInt(h2) < parseInt(h3)) {
                        alert("h2<h3");
                    }            
                    return false;
                });
            });
    </script>
    
     <asp:GridView ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
    
                    <Columns>
                        <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
                        <asp:TemplateField HeaderText="Header 1">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    
                        <asp:TemplateField HeaderText="Header 2">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
    
                        <asp:TemplateField HeaderText="Header 3">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                            </ItemTemplate>
                            <FooterStyle HorizontalAlign="Right" />
                            <FooterTemplate>                          
                                <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click" />
                            </FooterTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkSelect" runat="server" Text="Select" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

    The result:

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 24, 2019 7:30 AM
  • User-807418713 posted

    Thank You For Your Code

    Tuesday, September 24, 2019 8:27 AM
  • User288213138 posted

    Hi Gopi.MCA,

    Because the button was rewritten after the UpdatePanel partial refresh and the entire DOM tree was not reloaded, jQuery's ready event was not triggered and button lost its special effects.

    You can extract the code executed in the ready event, and then execute the jQuery initialization code after each UpdatePanel partial refresh by capturing the ScriptManager's EndRequest event.

    The code:

    <script type="text/javascript">
            function pageLoad() {
                $("[id*=Gridview1]").find("[id*=lnkSelect]").click(function () {
                    var row = $(this).closest("tr");
                    var h2 = row.find("td").eq(2).find("input").eq(0).val();
                    var h3 = row.find("td").eq(3).find("input").eq(0).val();
                    if (parseInt(h2) > parseInt(h3)) {
                        alert("h2>h3");
                    }
                    if (parseInt(h2) < parseInt(h3)) {
                        alert("h2<h3");
                    }
    
                });
            }               
    </script>

    Best regards,

    Sam

    Tuesday, September 24, 2019 8:57 AM