【问题标题】:Gridview and objectDatasourceGridview 和 objectDatasource
【发布时间】:2011-07-05 08:24:34
【问题描述】:

我正在尝试将其绑定到 gridview..

 var source = from p in allComments
                 select new { p.Img, p.Name, p.Comment };
    GridView1.DataSource = source;
    GridView1.DataBind();

所有评论都有 但它不会绑定,因为我的 gridview 允许分页。我读了一些关于这个问题的信息,我发现绑定了gridview,我可以使用ObjectDataSource ...并返回一个数据集以绑定到gridview..

我已经得到了gridview的这个标记(只是标记的一部分):

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

你怎么看..我应该使用 objectdataSource 吗?

【问题讨论】:

    标签: .net asp.net gridview objectdatasource


    【解决方案1】:

    如果您使用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

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      相关资源
      最近更新 更多