c# - 当我们在设计器中指定列时,如何填充gridview?

标签 c# asp.net

我确实是这方面的新手,但有人可以告诉我当我在设计器中定义列时如何在 GridView 中添加值。我有一列 Buttonfield 类型。我的default.asax代码如下。

代码:

    <asp:GridView ID="gvTableHolding" runat="server" BackColor="White" 
    BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="3" Width="1184px" 
    BorderStyle="None" CssClass="DDGridView" 
        onrowcommand="gvTableHolding_RowCommand" ShowHeaderWhenEmpty="True"
        EmptyDataText=" No Data!" ViewStateMode="Enabled">

        <Columns>
            <asp:BoundField HeaderText="Holding Register " />
            <asp:BoundField HeaderText="Description" />
            <asp:BoundField HeaderText="Set Value" />
            <asp:ButtonField ButtonType="Button" ShowHeader="True" Text="ChangeValue" 
                CommandName="ChangeValue" HeaderText="Buttons" />
            <asp:BoundField HeaderText="Default Value" />
            <asp:BoundField HeaderText="Decimal" />
            <asp:BoundField HeaderText="Hex" />
        </Columns>

    <FooterStyle BackColor="White" ForeColor="#000066" />
    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="#000066" 
        HorizontalAlign="Left" />
    <RowStyle ForeColor="#000066" HorizontalAlign="Center"/>
    <SelectedRowStyle BackColor="#669999" ForeColor="White" Font-Bold="True" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#007DBB" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>

提前谢谢您!

最佳答案

我真的不知道为什么你想在按钮字段中显示列标题。您可以在 Column 标记内使用 TemplateFieldItemField,例如:

<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Holding Register " Visible="false">
                    <ItemTemplate>
                        <asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "Holding_Register")%>' ID="lblUserId"
                            runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Description" Visible="false">
                    <ItemTemplate>
                        <asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "Description")%>' ID="lblUserId"
                            runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

关于c# - 当我们在设计器中指定列时,如何填充gridview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15476058/

相关文章:

c# - 如何比较 asp.net 网站中输入字符串的最后 3 个字符

c# - 发布后重新加载当前 View

asp.net - ASP 到 ASP.NET session 变量

c# - 使用第二个 UpdatePanel 的 gridview 中的 LinkBut​​ton 从第一个 UpdatePanel 更新文本框。找不到控件

asp.net - RadioButtonList 的 SelectedIndexChange 上的 JavaScript "confirm"

asp.net - 如何通过 Web 部署在 Visual Studio 中部署网站项目?

c# - 设置MDI-Parent Form的可用区域

c# - JObject 和 DotLiquid

c# - 如何以通用方式编写以下逻辑?

asp.net - asp.net/C#中嵌套 GridView 的查询