1

我有一个gridview,其中有两个链接按钮。这里是:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="5" OnRowCommand="gv_RowCommand" 
                        AllowPaging="true" DataKeyNames="ID" CssClass="mGrid"  BackColor="White" BorderColor="Silver" BorderStyle="Double"
                        BorderWidth="1px" CellPadding="4" >

         <RowStyle BackColor="White" Width="150%" ForeColor="#003399" />
            <Columns>
                <asp:TemplateField HeaderText="ID" Visible="false" >
                    <ItemTemplate>
                                    <asp:Label ID="lblID"  Text='<%#Bind("ID") %>' runat="server"></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField  HeaderText="Version">
                    <ItemTemplate>
                                    <asp:Label ID="lblversion" Text='<%#Bind("version") %>' runat="server"></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Image ID">
                    <ItemTemplate>
                                    <asp:Label ID="lblimageid" runat="server" Text='<%#Bind("image_id") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Getty ID">
                    <ItemTemplate>
                                    <asp:Label ID="lblgettyid" runat="server" Text='<%#Bind("getty_id") %>'></asp:Label>
                    </ItemTemplate>
                    <%--<EditItemTemplate>
                                    <asp:TextBox ID="txtgettyid" Text='<%#Bind("getty_id") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>--%>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Pool Letter">
                    <ItemTemplate>
                                    <asp:Label ID="lblpoolletter" runat="server" Text='<%#Bind("pool_letter") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="To Use">
                    <ItemTemplate>
                                    <asp:Label ID="lbltouse" runat="server" Text='<%#Bind("to_use") %>'></asp:Label>
                    </ItemTemplate>
                   <%-- <EditItemTemplate>
                                    <asp:TextBox ID="txttouse" Text='<%#Bind("to_use") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>--%>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Clue">
                    <ItemTemplate>
                                    <asp:Label ID="lblclue" runat="server" Text='<%#Bind("clue") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Range">
                    <ItemTemplate>
                                    <asp:Label ID="lblrange" runat="server" Text='<%#Bind("range") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="last_updated">
                    <ItemTemplate>
                                    <asp:Label ID="lbllastupdated" runat="server" Text='<%#Bind("last_updated") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Status">
                    <ItemTemplate>
                                    <asp:Label ID="lblstatus" runat="server" Text='<%#Bind("status") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField  HeaderText="First">
                    <ItemTemplate>
                                    <asp:Label ID="lblfirst" runat="server" Text='<%#Bind("first") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Middle">
                    <ItemTemplate>
                                    <asp:Label ID="lblmiddle" runat="server" Text='<%#Bind("middle") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Last">
                    <ItemTemplate>
                                    <asp:Label ID="lbllast" runat="server" Text='<%#Bind("last") %>'></asp:Label>
                    </ItemTemplate>

                </asp:TemplateField>
                 <asp:TemplateField >
                 <ItemStyle Wrap="false" Width="100px" />
                    <ItemTemplate>
                                    <asp:LinkButton ID="lnkbtnedit" Text="Edit" Visible="true" style="color:#006699;"  CommandName="Edit" runat="server"></asp:LinkButton>
                      &nbsp;&nbsp; <asp:LinkButton ID="lnkbtndel" Text="Delete" Visible="true"  style="color:#006699;"  CommandName="Delete" runat="server">  </asp:LinkButton>
                    </ItemTemplate>

                </asp:TemplateField>




            </Columns>
              <PagerStyle BackColor="#006699" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
                        <AlternatingRowStyle BackColor="#CCFFFF" />
                        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                        <HeaderStyle  BackColor="#006699" Font-Bold="True" ForeColor="White"  />
    </asp:GridView>









void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow row = GridView1.Rows[e.RowIndex];

            int ID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);

            con = new SqlConnection(conString);
            con.Open();
            int v = version + 1 ;

            string updatedetails = "update tblfameface set status ='Deleted',version=" + v + "  where ID=" + ID + " ";
            SqlCommand cmd = new SqlCommand(updatedetails, con);
            int temp = cmd.ExecuteNonQuery();
            con.Close();

            //int rows = GridView1.CurrentCell.RowIndex;
            //GridView1.Rows.RemoveAt(rows);

            bindDB();

            LinkButton btndel = (LinkButton)GridView1.Rows[row.RowIndex].FindControl("lnkbtndel");
            btndel.Visible = false;

        }

单击编辑链接时,它按需要工作,当我单击删除链接时,我希望隐藏该行。应该触发哪个事件以及如何处理?我怎样才能做到这一点?

4

2 回答 2

0
private void button1_Click(object sender, EventArgs e)
{
  int row = dataGridView1.CurrentCell.RowIndex;
  dataGridView1.Rows.RemoveAt(row);
} 

试试这个代码............

于 2013-04-12T10:09:51.463 回答
0

这是 Aspx:

<Columns>
 <asp:TemplateField HeaderText="Hide"> <ItemTemplate> <asp:LinkButton ID="lnkHide" runat="server" Text="Hide" OnClick="LnkHide_Click" /> </ItemTemplate> </asp:TemplateField>
            <asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>

这是背后的代码:

 protected void LnkHide_Click(object sender, EventArgs e)
    {
        GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
        clickedRow.Visible = false;
    }

试试这个代码

于 2013-04-12T11:26:55.643 回答