asp.net gridview:如何在一列中有多个按钮字段? [英] asp.net gridview: How can I have multple button fields in one column?
问题描述
我需要为gridview创建多个动作 - 比如说批准,拒绝和返回。
我可以通过创建一个
< asp:ButtonField ButtonType =LinkCommandName =ApproveText =Approve />
< asp:ButtonField ButtonType =LinkCommandName =DenyText =Deny />
< asp:ButtonField ButtonType =LinkCommandName =ReturnText =Deny />
然而,这会为每个按钮创建一个列。
是否有一种方法具有相同的功能,但将它们合并为一个列?
您是否考虑过使用 TemplateField
?下面是一个例子:
< ; asp:GridView ID =grdTestrunat =server>
< Columns>
< asp:TemplateField>
< ItemTemplate>
< asp: LinkButton ID =btnApproverunat =serverCommandName =ApproveText =Approve/>
< asp:LinkButton ID =btnReturnrunat =serverCommandName =ReturnText =Return/>
< / ItemTemplate中>
< / asp:TemplateField>
< /列>
< / asp:GridView>
您可以使用 OnRowCommand $完全相同的方式捕获命令c $ c>或做任何你喜欢的事情。您可以完全控制它的行为方式,而不受使用常规预定义列类型的内置功能的限制。
I need to create multiple actions for a gridview - say, "Approve", "Deny", and "Return".
I can do this by creating a button field for each action:
<asp:ButtonField ButtonType="Link" CommandName="Approve" Text="Approve" />
<asp:ButtonField ButtonType="Link" CommandName="Deny" Text="Deny />
<asp:ButtonField ButtonType="Link" CommandName="Return" Text="Deny" />
However, this creates one column for each button.
Is there a way to have the same functionality, but combine them into a single column?
Have you considered using an TemplateField
? Here is an example:
<asp:GridView ID="grdTest" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnApprove" runat="server" CommandName="Approve" Text="Approve" />
<asp:LinkButton ID="btnDeny" runat="server" CommandName="Deny" Text="Deny" />
<asp:LinkButton ID="btnReturn" runat="server" CommandName="Return" Text="Return" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can then capture the commands the exact same way using OnRowCommand
or do whatever you like. You have full control to make it behave how you need and not be bound by the built in functionality of using the regular predefined column types.
这篇关于asp.net gridview:如何在一列中有多个按钮字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!