Question : convert from repeater to gridview

I need help on the following to convert to gridview.

<table class=content cellspacing=1 cellpadding=0 width=100%>
<tr>
      <td class=header1 colspan=6><%# GetText(IsSentItems ? "sentitems" : "title") %></td>
</tr>
<tr class=header2>
      <td>&nbsp;</td>
      <td><img runat="server" id="SortSubject" align="absmiddle"/> <asp:linkbutton runat="server" id="SubjectLink"/></td>
      <td><img runat="server" id="SortFrom" align="absmiddle"/> <asp:linkbutton runat="server" id="FromLink"/></td>
      <td><img runat="server" id="SortDate" align="absmiddle"/> <asp:linkbutton runat="server" id="DateLink"/></td>
      <td>&nbsp;</td>
</tr>

<asp:repeater id=Inbox runat=server>
<FooterTemplate>
      <tr class=footer1>
            <td colspan="6" align="right"><asp:button runat="server" onload="DeleteSelected_Load" commandname="delete" text='<%# GetText("deleteselected") %>'/></td>
      </tr>
      </table>
</FooterTemplate>
<ItemTemplate>
      <tr class=post>
            <td align="center"><img src='<%# GetImage(Container.DataItem) %>'/></td>
            <td><a href='<%# yaf.Forum.GetLink(yaf.Pages.cp_message,"pm={0}",DataBinder.Eval(Container.DataItem,"UserPMessageID")) %>'><%# HtmlEncode(DataBinder.Eval(Container.DataItem,"Subject")) %></a></td>
            <td><%# DataBinder.Eval(Container.DataItem,IsSentItems ? "ToUser" : "FromUser") %></td>
            <td><%# FormatDateTime((System.DateTime)((System.Data.DataRowView)Container.DataItem)["Created"]) %></td>
            <td align="center"><asp:checkbox runat="server" id="ItemCheck" /></td>
            <asp:label runat="server" id="UserPMessageID" visible="false" text='<%# DataBinder.Eval(Container.DataItem,"UserPMessageID") %>'/>
      </tr>
</ItemTemplate>
</asp:repeater>

I appreciate it.

Answer : convert from repeater to gridview

Just looking over your previous code, I see a lot of things that won't be necessary/good idea to use when using a GridView.  Here is my advice before you start working on the front end - create a query that returns exactly what you want in your grid.  Not that it's impossible to reformat things in a gridview, just from my experience, it's much easier to work with grids when the data you are binding to it is what you want in the grid.

Also, I have found using an ObjectDataSource as the data source of a gridview is hands-down the best implementation.  If you don't know anything about ObjectDataSources, you should really read about them.  Essentially, you create a function in a class in your project that returns a dataset (usually from a database select statement).  You then indicate that function in your datasource.  Finally, you identify that ObjectDataSource ID as the DataSourceID of the GridView.  The reason I like this approach the best is you can then put the GridView and ObjectDataSource in an UpdatePanel and the whole thing will just "work" asynchronously (like paging and sorting).

Anyway, this should get you started.

        <asp:GridView runat="server" ID="id1" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="True">
            <Columns>
                <asp:ImageField DataImageUrlField="RowImageURL" />
                <asp:HyperLinkField DataNavigateUrlFields="SubjectURL" DataTextField="Subject" HeaderText="Subject" SortExpression="Subject" />
                <asp:BoundField HeaderText="From/To" DataField="FromUser" SortExpression="FromUser" />
                <asp:BoundField HeaderText="Date" DataField="Created" SortExpression="Created" />
                <asp:CheckBoxField  />
            </Columns>
        </asp:GridView>

Random Solutions  
 
programming4us programming4us