locked
apply mouse over row higlight and remove zero from repater RRS feed

Answers

  • User2103319870 posted

    Gopi.MCA

    1) On mouse over I want to highlight row

    You can use Jquey addClass method to highlight the cells. 

    First add id field to Repeater table like below

     <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                <HeaderTemplate>
                    <table class="table table-bordered bg-secondary" id="table1">
                        <thead>
    
                            <tr>
                                <th class="text-center">BatchNo</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center" colspan="2">Dep1</th>
                                <th class="text-center" colspan="2">Dep2</th>
                                <th class="text-center" colspan="2">Total For Dep1&Dep2</th>
                            </tr>
                            <tr>
                                <th></th>
                                <th></th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center">Total Value</th>
                            </tr>
    
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td runat="server" id="tdBatchno" class="text-center"><%# Eval("BatchNo") %></td>
                        <td runat="server" id="tdTotal_Qty" class="text-center"><%# Eval("Total_Qty") %></td>
                        <td runat="server" id="tdDep1Qty" class="text-center"><%# Eval("Dep1Qty") %></td>
                        <td runat="server" id="tdDep1Value" class="text-center"><%# Eval("Dep1Value") %></td>
                        <td runat="server" id="tdDep2Qty" class="text-center"><%# Eval("Dep2Qty") %></td>
                        <td runat="server" id="tdDep2Value" class ="text-center"><%# Eval("Dep2Value") %></td>
                        <td runat="server" id="tdTotalQty" class="text-center"><%# Eval("TotalQty") %></td>
                        <td runat="server" id="tdTotalValue" class="text-center"><%# Eval("TotalValue") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td class="text-center">Total</td>
                        <td class="text-center">
                            <asp:Literal ID="TotalQTY" runat="server"></asp:Literal></td>
                        <td class="text-center">
                            <asp:Literal ID="TotalValue" runat="server"></asp:Literal></td>
                    </tr>
                    </tbody>
            </table>
                </FooterTemplate>
            </asp:Repeater>

    Then add the below css class to your page

     <style type="text/css">
            .highlight {
                background-color: #ffff00;
            }
        </style>

    This css style we use to hight light the cell. After this you can use the Jquery codes to highlight the row in Repeater

     <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                //Attach hover event to each row in Gridview
                $("[id*=table1] tr").mouseover(function () {
                    //Assign the highlight css on mouseover
                    $(this).addClass("highlight");
                });
                //Attach mouseout event to each row in Gridview
                $("[id*=table1] tr").mouseout(function () {
                    //Remove the highlight css on mouseover
                    $(this).removeClass("highlight");
                });
            });
        </script>

    Demo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 19, 2018 12:54 AM
  • User2103319870 posted

    Remove zero values from repeater for example see B3 Batch No Dep1 Qty Value Is (zero 0) want to remove which comes zero.

    You can use ItemDatabound Event in Repeater to remove values from row which are zero. First we will assign a id to table cell from repeater and then check if value is zero. if its is zero then assign an empty string to cells.

       <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                <HeaderTemplate>
                    <table class="table table-bordered bg-secondary" id="table1">
                        <thead>
    
                            <tr>
                                <th class="text-center">BatchNo</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center" colspan="2">Dep1</th>
                                <th class="text-center" colspan="2">Dep2</th>
                                <th class="text-center" colspan="2">Total For Dep1&Dep2</th>
                            </tr>
                            <tr>
                                <th></th>
                                <th></th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center">Total Value</th>
                            </tr>
    
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td runat="server" id="tdBatchno" class="text-center"><%# Eval("BatchNo") %></td>
                        <td runat="server" id="tdTotal_Qty" class="text-center"><%# Eval("Total_Qty") %></td>
                        <td runat="server" id="tdDep1Qty" class="text-center"><%# Eval("Dep1Qty") %></td>
                        <td runat="server" id="tdDep1Value" class="text-center"><%# Eval("Dep1Value") %></td>
                        <td runat="server" id="tdDep2Qty" class="text-center"><%# Eval("Dep2Qty") %></td>
                        <td runat="server" id="tdDep2Value" class ="text-center"><%# Eval("Dep2Value") %></td>
                        <td runat="server" id="tdTotalQty" class="text-center"><%# Eval("TotalQty") %></td>
                        <td runat="server" id="tdTotalValue" class="text-center"><%# Eval("TotalValue") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td class="text-center">Total</td>
                        <td class="text-center">
                            <asp:Literal ID="TotalQTY" runat="server"></asp:Literal></td>
                        <td class="text-center">
                            <asp:Literal ID="TotalValue" runat="server"></asp:Literal></td>
                    </tr>
                    </tbody>
            </table>
                </FooterTemplate>
            </asp:Repeater>

    Then use below code to remove zero values

     protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    DataRowView drv = e.Item.DataItem as DataRowView;
                    HtmlTableCell tdDep1Qty = (HtmlTableCell)e.Item.FindControl("tdDep1Qty");
                    if (tdDep1Qty.InnerText == "0")
                    {
                        tdDep1Qty.InnerText = "";
                    }
                    HtmlTableCell tdBatchno = (HtmlTableCell)e.Item.FindControl("tdBatchno");
                    if (tdBatchno.InnerText == "0")
                    {
                        tdBatchno.InnerText = "";
                    }
                    HtmlTableCell tdTotal_Qty = (HtmlTableCell)e.Item.FindControl("tdTotal_Qty");
                    if (tdTotal_Qty.InnerText == "0")
                    {
                        tdTotal_Qty.InnerText = "";
                    }
                    HtmlTableCell tdDep1Value = (HtmlTableCell)e.Item.FindControl("tdDep1Value");
                    if (tdDep1Value.InnerText == "0")
                    {
                        tdDep1Value.InnerText = "";
                    }
                    HtmlTableCell tdDep2Qty = (HtmlTableCell)e.Item.FindControl("tdDep2Qty");
                    if (tdDep2Qty.InnerText == "0")
                    {
                        tdDep2Qty.InnerText = "";
                    }
                    HtmlTableCell tdDep2Value = (HtmlTableCell)e.Item.FindControl("tdDep2Value");
                    if (tdDep2Value.InnerText == "0")
                    {
                        tdDep2Value.InnerText = "";
                    }
                    HtmlTableCell tdTotalQty = (HtmlTableCell)e.Item.FindControl("tdTotalQty");
                    if (tdTotalQty.InnerText == "0")
                    {
                        tdTotalQty.InnerText = "";
                    }
                    HtmlTableCell tdTotalValue = (HtmlTableCell)e.Item.FindControl("tdTotalValue");
                    if (tdTotalValue.InnerText == "0")
                    {
                        tdTotalValue.InnerText = "";
                    }
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 19, 2018 12:58 AM

All replies

  • User2103319870 posted

    Gopi.MCA

    1) On mouse over I want to highlight row

    You can use Jquey addClass method to highlight the cells. 

    First add id field to Repeater table like below

     <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                <HeaderTemplate>
                    <table class="table table-bordered bg-secondary" id="table1">
                        <thead>
    
                            <tr>
                                <th class="text-center">BatchNo</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center" colspan="2">Dep1</th>
                                <th class="text-center" colspan="2">Dep2</th>
                                <th class="text-center" colspan="2">Total For Dep1&Dep2</th>
                            </tr>
                            <tr>
                                <th></th>
                                <th></th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center">Total Value</th>
                            </tr>
    
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td runat="server" id="tdBatchno" class="text-center"><%# Eval("BatchNo") %></td>
                        <td runat="server" id="tdTotal_Qty" class="text-center"><%# Eval("Total_Qty") %></td>
                        <td runat="server" id="tdDep1Qty" class="text-center"><%# Eval("Dep1Qty") %></td>
                        <td runat="server" id="tdDep1Value" class="text-center"><%# Eval("Dep1Value") %></td>
                        <td runat="server" id="tdDep2Qty" class="text-center"><%# Eval("Dep2Qty") %></td>
                        <td runat="server" id="tdDep2Value" class ="text-center"><%# Eval("Dep2Value") %></td>
                        <td runat="server" id="tdTotalQty" class="text-center"><%# Eval("TotalQty") %></td>
                        <td runat="server" id="tdTotalValue" class="text-center"><%# Eval("TotalValue") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td class="text-center">Total</td>
                        <td class="text-center">
                            <asp:Literal ID="TotalQTY" runat="server"></asp:Literal></td>
                        <td class="text-center">
                            <asp:Literal ID="TotalValue" runat="server"></asp:Literal></td>
                    </tr>
                    </tbody>
            </table>
                </FooterTemplate>
            </asp:Repeater>

    Then add the below css class to your page

     <style type="text/css">
            .highlight {
                background-color: #ffff00;
            }
        </style>

    This css style we use to hight light the cell. After this you can use the Jquery codes to highlight the row in Repeater

     <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                //Attach hover event to each row in Gridview
                $("[id*=table1] tr").mouseover(function () {
                    //Assign the highlight css on mouseover
                    $(this).addClass("highlight");
                });
                //Attach mouseout event to each row in Gridview
                $("[id*=table1] tr").mouseout(function () {
                    //Remove the highlight css on mouseover
                    $(this).removeClass("highlight");
                });
            });
        </script>

    Demo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 19, 2018 12:54 AM
  • User2103319870 posted

    Remove zero values from repeater for example see B3 Batch No Dep1 Qty Value Is (zero 0) want to remove which comes zero.

    You can use ItemDatabound Event in Repeater to remove values from row which are zero. First we will assign a id to table cell from repeater and then check if value is zero. if its is zero then assign an empty string to cells.

       <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                <HeaderTemplate>
                    <table class="table table-bordered bg-secondary" id="table1">
                        <thead>
    
                            <tr>
                                <th class="text-center">BatchNo</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center" colspan="2">Dep1</th>
                                <th class="text-center" colspan="2">Dep2</th>
                                <th class="text-center" colspan="2">Total For Dep1&Dep2</th>
                            </tr>
                            <tr>
                                <th></th>
                                <th></th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Qty</th>
                                <th class="text-center">Value</th>
                                <th class="text-center">Total Qty</th>
                                <th class="text-center">Total Value</th>
                            </tr>
    
                        </thead>
                        <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td runat="server" id="tdBatchno" class="text-center"><%# Eval("BatchNo") %></td>
                        <td runat="server" id="tdTotal_Qty" class="text-center"><%# Eval("Total_Qty") %></td>
                        <td runat="server" id="tdDep1Qty" class="text-center"><%# Eval("Dep1Qty") %></td>
                        <td runat="server" id="tdDep1Value" class="text-center"><%# Eval("Dep1Value") %></td>
                        <td runat="server" id="tdDep2Qty" class="text-center"><%# Eval("Dep2Qty") %></td>
                        <td runat="server" id="tdDep2Value" class ="text-center"><%# Eval("Dep2Value") %></td>
                        <td runat="server" id="tdTotalQty" class="text-center"><%# Eval("TotalQty") %></td>
                        <td runat="server" id="tdTotalValue" class="text-center"><%# Eval("TotalValue") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td class="text-center">Total</td>
                        <td class="text-center">
                            <asp:Literal ID="TotalQTY" runat="server"></asp:Literal></td>
                        <td class="text-center">
                            <asp:Literal ID="TotalValue" runat="server"></asp:Literal></td>
                    </tr>
                    </tbody>
            </table>
                </FooterTemplate>
            </asp:Repeater>

    Then use below code to remove zero values

     protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    DataRowView drv = e.Item.DataItem as DataRowView;
                    HtmlTableCell tdDep1Qty = (HtmlTableCell)e.Item.FindControl("tdDep1Qty");
                    if (tdDep1Qty.InnerText == "0")
                    {
                        tdDep1Qty.InnerText = "";
                    }
                    HtmlTableCell tdBatchno = (HtmlTableCell)e.Item.FindControl("tdBatchno");
                    if (tdBatchno.InnerText == "0")
                    {
                        tdBatchno.InnerText = "";
                    }
                    HtmlTableCell tdTotal_Qty = (HtmlTableCell)e.Item.FindControl("tdTotal_Qty");
                    if (tdTotal_Qty.InnerText == "0")
                    {
                        tdTotal_Qty.InnerText = "";
                    }
                    HtmlTableCell tdDep1Value = (HtmlTableCell)e.Item.FindControl("tdDep1Value");
                    if (tdDep1Value.InnerText == "0")
                    {
                        tdDep1Value.InnerText = "";
                    }
                    HtmlTableCell tdDep2Qty = (HtmlTableCell)e.Item.FindControl("tdDep2Qty");
                    if (tdDep2Qty.InnerText == "0")
                    {
                        tdDep2Qty.InnerText = "";
                    }
                    HtmlTableCell tdDep2Value = (HtmlTableCell)e.Item.FindControl("tdDep2Value");
                    if (tdDep2Value.InnerText == "0")
                    {
                        tdDep2Value.InnerText = "";
                    }
                    HtmlTableCell tdTotalQty = (HtmlTableCell)e.Item.FindControl("tdTotalQty");
                    if (tdTotalQty.InnerText == "0")
                    {
                        tdTotalQty.InnerText = "";
                    }
                    HtmlTableCell tdTotalValue = (HtmlTableCell)e.Item.FindControl("tdTotalValue");
                    if (tdTotalValue.InnerText == "0")
                    {
                        tdTotalValue.InnerText = "";
                    }
                }
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 19, 2018 12:58 AM