0

我有一个gridview,我显示itbutton 属性为false,showdeletebutton 属性为true。Edit 是一个链接按钮,单击它时会触发一个行命令事件。

现在,我的问题是,在 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>

                </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>

                </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 >
                    <ItemTemplate>
                                    <asp:LinkButton ID="lnkbtnedit" Text="Edit" style="color:#003399;" CommandName="Edit" runat="server"></asp:LinkButton>
                    </ItemTemplate>

                </asp:TemplateField>


                 <asp:CommandField  ShowDeleteButton="true" CausesValidation="false" />

            </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>

我能得到任何帮助吗?

4

2 回答 2

1

您可以在您的 : 中包含删除按钮ItemTemplate

<asp:TemplateField>
    <ItemTemplate>
        <asp:LinkButton ID="lnkbtnedit" Text="Edit" style="color:#003399;" CommandName="Edit" runat="server"></asp:LinkButton>
        <asp:LinkButton ID="lnkbtndelete" Text="Delete" style="color:#003399;" CommandName="Delete" runat="server"></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>

然后只需删除CommandField.

于 2013-04-12T19:32:11.400 回答
0

替换您的以下代码

<asp:TemplateField >
      <ItemTemplate>
         <asp:LinkButton ID="lnkbtnedit" Text="Edit" style="color:#003399;"
           CommandName="Edit" runat="server"></asp:LinkButton>
      </ItemTemplate>

</asp:TemplateField>


<asp:CommandField  ShowDeleteButton="true" CausesValidation="false" />

使用此代码。

 <asp:TemplateField  ItemStyle-HorizontalAlign="Center"  ItemStyle-VerticalAlign="Top"
    HeaderStyle-Width="10%">
     <ItemTemplate>
         <asp:LinkButton ID="lnkbtnedit" runat="server" CommandName="Edit" Text="Edit" />
     </ItemTemplate>

     <EditItemTemplate>                               
       <asp:LinkButton ID="btndelete" runat="server" CommandName="Delete" Text="Delete"     
          CommandArgument="<%#((GridViewRow)Container).RowIndex%>"/>

     </EditItemTemplate>             

 </asp:TemplateField>
于 2013-04-12T04:23:35.170 回答