【问题标题】:GridView adding column with buttonGridView用按钮添加列
【发布时间】:2014-09-22 19:00:11
【问题描述】:

我需要在 GridView 中添加带有按钮的列吗?我与 asp:button 我有错误我也试过 asp:ButtonField 我得到了这个错误:

“创建控件时出错 - narudzbaGridType 'System.Web.UI.WebControls.ButtonField' 没有名为 'ID' 的公共属性。

但我为我的 Button 字段提供了 ID 名称 asp:ButtonField ID="example"

<asp:GridView ID="narudzbaGrid" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="Let" HeaderText="Let"/>
            <%--<asp:BoundField DataField="Kolicina" HeaderText="Kolicina"/>--%>
        </Columns>
</asp:GridView>

【问题讨论】:

  • 这是一个错误,因为 ButtonField 没有 ID 属性。

标签: c# asp.net gridview


【解决方案1】:

您可以像这样使用TemplateField(添加到列块):

<asp:templatefield headertext="Author Name">
    <itemtemplate>
      <asp:button id="buttonl"
        Text= 'Click Me'
        runat="server"/> 
    </itemtemplate>
  </asp:templatefield>

【讨论】:

    【解决方案2】:

    您好,您需要添加一个TemplateField。每个人都喜欢使用ImageButton,但如果您想使用其他控件,请继续。

    <asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center" >
      <ItemTemplate>
         <asp:ImageButton ID="imgBtnEditar" runat="server" ImageUrl="~/iconos/Image.png" CommandName="edit" ToolTip="Edit">
         </asp:ImageButton>
      </ItemTemplate>
      <ItemStyle Height="8px"></ItemStyle>                                
    </asp:TemplateField>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多