开发者

Gridview and objectDatasource

开发者 https://www.devze.com 2023-03-17 13:39 出处:网络
I am trying to bind this to a gridview.. var source = from p in allComments select new { p.Img, p.Name, p.Comment };

I am trying to bind this to a gridview..

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

all Comments has But it wont bind cause my gridview allows paging. I read a bit about that problem and i found to bind the gridview ,, i could use ObjectDataSource... And return a dataset to bind to the gridview..

I have got this mark up of the gridview (only part of the mark up):

      <asp:TemplateField He开发者_Python百科aderText="#">
                    <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?


If you use ObjectDataSource, then Paging and Sorting will automatically work. I would recommend you to use the ObjectDataSource as it has many other features that you can use, like caching etc... Please check this link Displaying Data With the ObjectDataSource

Check out this for more about ObjectDataSource http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号