我有一个Gridview,我想为添加的每一行添加一个“操作”按钮,点击后可以编辑或删除一行。
在我的图片中,它看起来像一个下拉列表。我更喜欢按钮,但是下拉列表将作为最后的手段。
这是我到目前为止所尝试的:
<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>
答案 0 :(得分:0)
尝试以下方法:
<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>
您可以按照自己喜欢的方式参考图像。
答案 1 :(得分:0)
任何原因它只能限于一列?然后你可以使用:
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
......与确定选择了哪个下拉项目相比,这个连接非常容易。