1

我有一个gridview,单击删除按钮时,我需要删除该行一段时间,单击撤消链接时,我需要重新显示该行。

我的gridview代码如下所示:

  <asp:GridView ID="NotificationHistory" runat="server" AllowPaging="True"
        AutoGenerateColumns="False" DataKeyNames="Id" 
        ShowHeader="False" PagerSettings-Mode="NumericFirstLast"
        FooterStyle-BorderStyle="None" EnableViewState="False" GridLines="None" >
        <PagerSettings Mode="NumericFirstLast"></PagerSettings>
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <img alt="Delete" title="Delete" src="SiteImages/X.gif" 
                        onclick="changeImage(this)" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ItemName") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ItemName") %>'></asp:Label>
                </ItemTemplate>

            </asp:TemplateField>
            <asp:TemplateField HeaderText="Status">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle BorderColor="#F1E8E8" BorderStyle="Solid" BorderWidth="1px" CssClass="gridItemAlignment" />
            </asp:TemplateField>
            <asp:BoundField DataField="Id" HeaderText="ID" Visible="false" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="ImgDelete" runat="server" Width="16px" Height="16px" CommandName="Remove"
                        ImageUrl="SiteImages/X.gif" ClientIDMode="Static" Enabled="false" />
                    <asp:HiddenField ID="hFType" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <HeaderStyle Height="10px" BorderColor="Silver" BorderStyle="None" BorderWidth="0" />
        <FooterStyle BorderStyle="None"></FooterStyle>
        <PagerStyle HorizontalAlign="Right" BorderStyle="None" ForeColor="#999999"></PagerStyle>
        <EmptyDataTemplate>
            <asp:Label ID="lblHistory" runat="server">No History.</asp:Label>
        </EmptyDataTemplate>
    </asp:GridView>

我的 html :

<table id="ctl00_Content_NotificationHistory" class="home-history-grid" cellspacing="0" border="0" style="border-color: rgb(241, 232, 232); border-style: none; width: 100%; border-collapse: collapse;">
<tbody>
<tr class="home-history-grid-row">
<td>
<img height="16px" width="16px" onclick="changeImage(this)" src="SiteImages/X.gif" title="Delete" alt="Delete">
</td>
<td class="gridItemStyle" style="border: 1px solid rgb(241, 232, 232); width: 75%;">
<a href="ReportCreation.aspx?rid=207">Status Report for Kalista as on 05/03/2012</a>
</td>
<td class="gridItemAlignment" style="border: 1px solid rgb(241, 232, 232);">Saved</td>
<td>
<img id="ImgDelete" height="16px" width="16px" onclick="deleteRow(this)" src="SiteImages/X.gif" alt="">
<input id="ctl00_Content_NotificationHistory_ctl02_hFType" type="hidden" value="Cirrus.CirrusObjects.Report" name="ctl00$Content$NotificationHistory$ctl02$hFType">
</td>
</tr>
<tr class="home-history-grid-row">
<td>
</td>
<td class="gridItemStyle" style="border: 1px solid rgb(241, 232, 232); width: 75%;">
</td>
<td class="gridItemAlignment" style="border: 1px solid rgb(241, 232, 232);">Saved</td>
<td>
</td>
</tr>
</tbody>
</table>

我的javascript删除行(这是删除选定的行,现在我想知道如何在同一个地方重新显示它):

 function deleteRow(imageElement) {
            var img = $(imageElement);
            imageElement.setAttribute("id", "selectedRow");
            alert($("selectedRow").siblings(":image"));
            var row = $(imageElement).closest('tr');
            $(row).remove();
        }
4

2 回答 2

2

这将显示/隐藏该行

$(row).toggle();
于 2012-05-04T04:30:15.107 回答
1

将此 $(row).remove() 更改为

$(row).hide();它会被隐藏,当你想再次显示它时 $(row).show();

甚至这会更光滑

$(row).toggle();(在幕后它将设置 display='none' 隐藏)

于 2012-05-04T04:25:05.580 回答