【发布时间】: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总是空的并且它的列没有被渲染,因为它们是自动生成的?有什么想法吗??