我正在尝试将其绑定到网格视图..
var source = from p in allComments
select new { p.Img, p.Name, p.Comment };
GridView1.DataSource = source;
GridView1.DataBind();所有评论都有,但它不会绑定,因为我的网格视图允许分页。我读了一些关于这个问题的文章,我发现要绑定网格视图,我可以使用ObjectDataSource……并返回要绑定到网格视图的数据集。
我得到了这个网格视图的标记(只是标记的一部分):
<asp:TemplateField HeaderText="#">
<HeaderStyle Width="500px" />
<ItemStyle Width="500px" Height="100px" />
<ItemTemplate>
<asp:Label ID="lblMessage" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="#">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" Height="100px" />
<ItemTemplate>
<asp:Image ID="imgName" runat="server" imageUrl='<%# Bind("Img") %>'></asp:Image><br />
<asp:Hyperlink ID="hyperLink" runat="server" Text='<%# Bind("Name") %>' ></asp:Hyperlink>
</ItemTemplate>
</asp:TemplateField>What do you think..Should I use objectdataSource?
发布于 2011-07-05 16:28:40
如果您使用ObjectDataSource,那么Paging and Sorting将自动工作。我建议你使用ObjectDataSource,因为它有许多其他你可以使用的功能,比如caching等等。请检查此链接Displaying Data With the ObjectDataSource
有关ObjectDataSource http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx的更多信息,请查看此处
https://stackoverflow.com/questions/6579770
复制相似问题