CSharp - 在具有下拉菜单的gridview中,向每一行添加按钮

  显示原文与译文双语对照的内容

我有一个 Gridview,我希望在每行添加一个"操作"按钮,单击后会允许我编辑或者 delete 行。

我的照片看起来像一个下降的List 。 我喜欢一个按钮,然而一个dropdownlist将作为最后的resort 。

enter image description here 这是我迄今为止尝试过的:


 <asp:GridView runat="server" ID="grdvwDepositTransaction"
 AutoGenerateColumns="false" DataKeyNames="Status"
 OnRowCommand="grdvwDepositTransaction_RowCommand" ShowHeaderWhenEmpty="true" ShowFooter="true" OnRowDataBound="grd_RowDataBound"
 CssClass="grid" width="750">
 <HeaderStyle CssClass="HeaderTemplate"/>
 <FooterStyle CssClass="FooterTemplate"/>
 <Columns>
 <asp:TemplateField> 

 <ItemTemplate>
 <input onclick="javascript: showMenu(); return false;" onmouseout="javascript: hideMenu(); return false;" type="button" class="savebutton" value="Actions" id="actionMenuRowSomething"/>
 <ul id="actionMenuRow" style="display: none; margin-top: -6px; text-align: left; padding: 0px; margin-right: 0px;" onmouseover="javascript: showMenu(); return false;" onmouseout="javascript: hideMenu(); return false;" class="ui-menu">
 <li><a href="#" onclick="ShowHomeScreen();">something</a></li>
 <li>
 <asp:LinkButton ID="something" runat="server" Text="View Updates" style="width:100px;">works</asp:LinkButton>
 </li>
 </ul>
 </ItemTemplate>
 <EditItemTemplate>

 </EditItemTemplate>
 </asp:TemplateField> 
 <asp:BoundField DataField="DepositEntry.cardNumber" HeaderText="Card Number" ItemStyle-CssClass="mediumColumn columnCenter"/>
 <asp:BoundField DataField="DepositEntry.accountNumber" HeaderText="Account Number" ItemStyle-CssClass="mediumColumn columnCenter"/>
 <asp:BoundField DataField="DepositEntry.firstName" HeaderText="Customer Name" ItemStyle-CssClass="mediumColumn columnCenter"/>
 <asp:BoundField DataField="DepositEntry.transactionDateTime" HeaderText="Transaction Date/Time" ItemStyle-CssClass="mediumColumn columnCenter"/>
 <asp:BoundField DataField="DepositEntry.cashAmount" HeaderText="Cash Amount" ItemStyle-CssClass="mediumColumn columnCenter"/>
 <asp:BoundField DataField="DepositEntry.depositAmount" HeaderText="Envelope Deposit Amount" ItemStyle-CssClass="mediumColumn columnCenter"/>
 </Columns>

 <EmptyDataTemplate>
 <br/>
 <br/><br/>
 <span style="font-weight: bold; text-anchor:middle;">No Transactions have been entered</span>
 </EmptyDataTemplate> 
 </asp:GridView>

时间: 作者:

任何原因只能限制为一列? 然后你可以使用:


AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"

"。"。并且挂钩比选择哪个下拉项目更容易,等等。

请尝试以下操作:


 <asp:TemplateField HeaderText=""> 
 <EditItemTemplate>
 <asp:ImageButton ID="ibtnUpdate" runat="server" CommandName="Update" CausesValidation="true" ImageUrl="~/Content/Images/h.ico"/>
 <asp:ImageButton ID="ibtnCancel" runat="server" CommandName="Cancel" CausesValidation="false" ImageUrl="~/Content/Images/j.ico"/>
 </EditItemTemplate>
 <ItemTemplate>
 <asp:ImageButton ID="ibtnEdit" runat="server" CommandName="Edit" CausesValidation="false" ImageUrl="~/Content/Images/k.ico"/>
 <asp:ImageButton ID="ibtnDelete" runat="server" CommandName="Delete" CausesValidation="false" ImageUrl="~/Content/Images/l.ico"/>
 </ItemTemplate> 
 </asp:TemplateField>

你可以按自己喜欢的方式引用图像。

作者:
...