[英]asp.net c# change editbutton style programatically
我創建了一個網站,我有一個如下的網格視圖:
欲查詢帳號:<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" />
<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 “gridview”
但我想將我的編輯按鈕,更新按鈕,取消按鈕從linkbutton樣式更改為按鈕,我該怎么做?
您必須使用TemplateFields並在其中放置一些按鈕。 然后你必須給那些按鈕保留CommandName
如Edit,Update等。這些對應於OnRowUpdating
和OnRowEditing
事件。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.