简体   繁体   English

如何将按钮控件动态添加到GridView单元中? VB.NET

[英]How to add a button control dynamically into a GridView cell ? VB.NET

Look, it´s simple. 看,很简单。 I have a GridView which is populated with data from my database. 我有一个GridView,其中填充了数据库中的数据。

What I want is put a button in each cell that contains a specific datum. 我要在包含特定基准的每个单元格中放置一个按钮。

Pls, look the image below. 请看下面的图片。 It describes exactly what I want 它准确地描述了我想要的

In VB.NET, pls! 在VB.NET中,请! =) =)

Example Image 范例图片

Thanks very much! 非常感谢!

You are going to need to define the button control inside of the <Columns> section of your GridView markup, like this: 您将需要在GridView标记的<Columns>部分内定义按钮控件,如下所示:

<asp:gridview id="CustomersGridView" runat="server">
    <columns>
        <asp:boundfield datafield="DateColumn" headertext="Date"/>
        <asp:TemplateField>
            <HeaderTemplate>
                Positive
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label id="LabelPositive" runat="server" Text='<%# Eval("PositiveColumn")%>' />
                <br />
                <asp:Button id="ButtonPositive" runat="server" Text="Show" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <HeaderTemplate>
                Negative
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label id="LabelNegative" runat="server" Text='<%# Eval("NegativeColumn")%>' />
                <br />
                <asp:Button id="ButtonNegative" runat="server" Text="Show" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <HeaderTemplate>
                Neutral
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label id="LabelNeutral" runat="server" Text='<%# Eval("NeutralColumn")%>' />
                <br />
                <asp:Button id="ButtonNeutral" runat="server" Text="Show" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:boundfield datafield="NoCommentsColumn" headertext="No Comments"/>
        <asp:boundfield datafield="TotalColumn" headertext="Total"/>
    </columns>
</asp:gridview>

Note: The datafield and Eval() calls are bound to made up names like NeutralColumn and NoCommentsColumn , substitute those names with your real database field names. 注意: datafieldEval()调用绑定到由NeutralColumnNoCommentsColumn名称组成的名称,用真实的数据库字段名称替换这些名称。

You need to add while data binding the grid. 您需要在数据绑定网格时添加。 Look for an event call and handle your code there. 查找事件调用并在那里处理代码。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM