2012-09-26 54 views
1

我已绑定的GridView到LINQ结果和设置的AutoGenerateColumns为true,并启用视图状态的网格视图和所有还没呈现,HTML浏览器中显示为空的GridView不会呈现

<div></div> 

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

<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() 

请帮我

+0

是LINQ查询返回结果在现场ENV? –

+0

是的,你可以看到变量RESULTCOUNT个,它返回的实际行算作预期,但在GridView不存在**只有在线(互联网)**! –

+0

结果是,你是从,当然它会有个计数查询集合。在现场环境中,执行linq查询后,变量tmp是否有任何数据? – Sinaesthetic

回答

1

我发现,在我的代码没有错误,但没有被渲染为GridView的原因是,它是数据源是空的,因为尽管查询(结果)是没有什么第二个查询(TMP)实际上是空的,因为条件(其中p.ShowProduct),我认为它是真实的,检查db后,我发现,在这一领域的所有值都是零。

谢谢

+0

谢谢,这对我有用。我有一个完全动态的gridview,当它是空的时候没有被渲染。我不得不ShowHeaderWhenEmpty设置为true,它仍然只给了我“

”,但一个数据源设置为一个新的列表()非常完美,迫使它来呈现。 – Sam