asp.net gridview:如何在一列中有多个按钮字段? [英] asp.net gridview: How can I have multple button fields in one column?

查看:113
本文介绍了asp.net gridview:如何在一列中有多个按钮字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为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: LinkBut​​ton ID =btnApproverunat =serverCommandName =ApproveText =Approve/>
< asp:LinkBut​​ton ID =btnReturnrunat =serverCommandName =ReturnText =Return/>
< / ItemTemplate中>
< / asp:TemplateField>
< /列>
< / asp:GridView>

您可以使用 OnRowCommand 或做任何你喜欢的事情。您可以完全控制它的行为方式,而不受使用常规预定义列类型的内置功能的限制。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆