【问题标题】:Gridview not rendered网格视图未呈现
【发布时间】:2012-09-26 16:12:53
【问题描述】:

我已将 gridview 绑定到 Linq 结果并将 AutoGenerateColumns 设置为 true 并为网格视图启用 Viewstate 并且仍然没有呈现,浏览器中的 Html 显示为空

   <div></div>

奇怪的是,在文件系统中的 ASP.NET 开发服务器中,它是可见的,没有问题,但是当我将它托管在 Internet 上时,它不是!!

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <Triggers>
         <asp:asyncPostBackTrigger ControlID="Button1"  EventName="Click" />

 </Triggers>

<ContentTemplate >
   <asp:GridView dir="rtl" ID="GridView1" runat="server" AllowPaging="True" 
     AllowSorting="True" CellPadding="4"  AutoGenerateColumns="true" 
     ForeColor="#333333" GridLines="Vertical"  ViewStateMode="Enabled"
     Width="917px" style=" padding-bottom:20px;" EnableViewState="True">
    <AlternatingRowStyle BackColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" 
        HorizontalAlign="Right" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F5F7FB" />
    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
    <SortedDescendingCellStyle BackColor="#E9EBEF" />
    <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

  <br />
  <br />
</ContentTemplate>
</asp:UpdatePanel>

顺便说一句,我也尝试删除 Ajax 控件,但它没有解决问题

Linq 代码相当复杂,但我可以给你看

     tmp = (From p In results Where p.ShowProduct
            Select New With {.المادة = p.ProductName,
                                     .السعر = If(p.Setting.ShowPrices, If(p.ShowPrice, (p.SellPrice * p.Setting.ConversionToDollar).ToString, " - "), " - "),
                                        .الكمية = If(p.Setting.ShowCounts, If(p.ShowCount, CSng(p.Count) & " " & p.Unit, " - "), " - "),
                                        .الصنف = p.Category,
                                        .الوصف = p.Description,
                                        .المنشأ = p.Manufacturer,
                                        .المحل = If(p.Setting.ShowAddress,
                                                    If(p.Setting.ShowMobile,
                                                       p.Setting.NameOfShop & "/" & p.Setting.ShopAddress & "/" & p.Setting.Mobile,
                                                       p.Setting.NameOfShop & "/" & p.Setting.ShopAddress & "/ -"),
                                                   If(p.Setting.ShowMobile,
                                                      p.Setting.NameOfShop & "/ - /" & p.Setting.Mobile,
                                                  p.Setting.NameOfShop & "/ - / - ")),
                                     .التاريخ = p.LastUpdate}).ToList.OrderByDescending(Function(n) n.GetType().GetProperty(GridViewSortExpression).GetValue(n, Nothing)).ToList


    End If

    ResultCount = results.Count
    GridView1.DataSource = tmp
    ' GridView1.ViewStateMode = UI.ViewStateMode.Enabled
    GridView1.DataBind()

我也试过放这行代码

    UpdatePanel1.Update()

请帮帮我

【问题讨论】:

  • linq 查询是否在实时环境中返回结果?
  • 是的,您可以看到变量 ResultCount ,它按预期返回实际行数,但 gridview 不存在仅在线(互联网) !!!
  • Results 是您从中查询的集合,当然它会有一个计数。在live环境中,变量tmp在linq查询执行后是否有数据?
  • 是的 tmp 变量不是什么都不是,实际上我也尝试将结果作为数据源并没有发生任何事情,当我删除 gridview1.databind 时,我注意到一件事,gridview 也从开发环境中消失了,所以我在想如果实时环境中的数据以某种方式丢失并且gridview总是空的并且它的列没有被渲染,因为它们是自动生成的?有什么想法吗??

标签: asp.net gridview


【解决方案1】:

我发现我的代码中没有错误,但是没有呈现 Gridview 的原因是它是数据源是空的,因为虽然查询(结果)不是什么,但第二个查询(tmp)实际上是空的,因为我认为是 True 的条件 (Where p.ShowProduct) 在检查 Db 后我发现该字段中的所有值都是 Null 。

谢谢

【讨论】:

  • 谢谢,这对我有用。我有一个完全动态的网格视图,当它为空时没有被渲染。我将 ShowHeaderWhenEmpty 设置为 true,但它仍然只给了我 '
    ',但是将数据源设置为新的 List() 可以完美地强制它进行渲染。
猜你喜欢
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 2016-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多