【问题标题】:Changing GridView colujmn name in html doesn't change column name when displaying page显示页面时更改 html 中的 GridView 列名不会更改列名
【发布时间】:2012-10-26 13:42:01
【问题描述】:

我有一个我继承的项目。我被要求删除网站上 GridView 中的两列,并用另外两列替换它们。我已经更改了 html 以用新的替换原件,但是列标题名称似乎不想更改。我已经在调试器打开的情况下运行了代码,并在代码 c# 代码执行任何操作之前在代码的第一行放置了一个中断,并检查了 gridview 对象。它已经分配了这些列名,我不知道如何。我已经搜索了原始列名,但无法在任何地方找到它们。

基本上,我的问题是在页面真正加载之前控制列的名称是什么?每次我对此进行搜索时,都会有人想以编程方式对其进行更改,但这似乎不是我所知道的问题所在。我已经尝试像 here 建议的那样进入对象的属性,但它显示的是新字段而不是旧字段。

以下是创建此网格视图和对象的相关(我相信)HTML 代码。

<asp:GridView ID="gvTopSearch" runat="server" AllowPaging="True" 
    AllowSorting="True" PageSize="15" AutoGenerateColumns="False"
    DataKeyNames="NID,CID" Width="100%" OnPageIndexChanging="gvTopSearch_PageIndexChanging"
    OnSorting="gvTopSearch_Sorting" 
    onrowdatabound="gvTopSearch_RowDataBound" 
    meta:resourcekey="gvTopSearchResource1" >
    <Columns>
         <asp:TemplateField SortExpression="NewField1" HeaderText="NewField1" 
            meta:resourcekey="TemplateFieldResource5">
            <ItemTemplate>
                <%#Eval("NewField1")%>
            </ItemTemplate>
             <HeaderStyle Width="75px" />
        </asp:TemplateField>
        <asp:TemplateField SortExpression="NewField2" HeaderText="NewField2" 
            meta:resourcekey="TemplateFieldResource6">
            <ItemTemplate>
                <%#Eval("NewField2")%>
            </ItemTemplate>
            <HeaderStyle Width="75px" />
        </asp:TemplateField>
    </Columns>
    <AlternatingRowStyle CssClass="fieldName" HorizontalAlign="Left" />
    <EmptyDataTemplate>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center" style="padding-top: 50px; padding-bottom: 50px; padding-left: 60px;">
                    <img src="" alt="" />
                    <b>
                        </b>
                </td>
            </tr>
        </table>
    </EmptyDataTemplate>
    <HeaderStyle CssClass="fieldNamewithbgcolor" HorizontalAlign="Left" />
    <PagerStyle CssClass="Paging" />
    <RowStyle CssClass="gridbgcolor" HorizontalAlign="Left" />
</asp:GridView>

"NewField1" 和 "NewField2" 应该显示但没有显示。

【问题讨论】:

  • 你试过清理项目并重新构建它吗?
  • 您可以检查您的代码以确保没有在其中设置列名。我们的页面有时会这样做。此外,您正在使用 ctrl+f5 进行刷新,以确保您没有获得缓存版本,对吧?
  • 如果它给出了变量 newfield1 和 2 的值,它在 header 检查中给出了什么值?
  • 并检查页面的设计视图它在那里显示什么
  • 另外,列名可以在代码隐藏中设置一个标签(出于国际化目的),因此搜索原始列名可能无法显示您正在寻找的内容

标签: c# asp.net html gridview


【解决方案1】:

啊!我讨厌这个愚蠢的项目。我终于找到了问题所在(只用了大约 3 天)。

在同一目录中显然有一个 App_LocalResources 文件夹,其中包含一个 resx 文件。在该文件中是键值对,包括上面看到的“TemplateFieldResource5”和“TemplaceFieldResource6”,它们与旧的列名链接。我已将它们更改为新的列名,并且可以正常工作。

感谢那些试图在你的 cmets 上帮助我的人。如果这就是你所说的史蒂夫背后的代码的意思,我误解了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 2022-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多