asp.net c#以编程方式更改editbutton样式

时间:2018-03-17 08:29:28

标签: c# asp.net

我创建了一个网站,我有一个如下所示的网格视图:

欲查詢帳號:<asp:TextBox ID="txt_userid" runat="server"></asp:TextBox>
<br />
欲查詢日期:<asp:TextBox ID="txt_date" runat="server" TextMode="Date"></asp:TextBox>
<br />
<asp:Button ID="btn_isreplied" runat="server" Text="選擇尚未回覆" OnClick="btn_isreplied_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btn_search" runat="server" Text="查詢" OnClick="btn_search_Click" />
<br />
<br />

<asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" 
   OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" 
   OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating" 
   OnRowDeleting="GridView1_RowDeleting" 
   AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="sno">
    <AlternatingRowStyle BackColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

[1]:https://ppt.cc/fzgM9x&#34; gridview&#34;

但我想将我的编辑按钮,更新按钮,取消按钮从linkbutton样式更改为按钮,我该怎么办?

1 个答案:

答案 0 :(得分:3)

您必须使用TemplateFields并在其中放置一些按钮。然后你必须保留CommandName保留的按钮,如编辑,更新等。这些按钮对应于OnRowUpdatingOnRowEditing事件。

<asp:TemplateField>
    <ItemTemplate>
        <asp:Button ID="Button1" runat="server" CommandName="Edit" Text="Edit" />
        <asp:Button ID="Button2" runat="server" CommandName="Delete" Text="Delete" />
    </ItemTemplate>
    <EditItemTemplate>
        <asp:Button ID="Button3" runat="server" CommandName="Update" Text="Update" />
         <asp:Button ID="Button4" runat="server" CommandName="Cancel" Text="Cancel" />
    </EditItemTemplate>
</asp:TemplateField>