2012-09-26 52 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