DataTable dt = new DataTable(); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("Sender", typeof(string)); dt.Columns.Add("DateCreated", typeof(string)); dt.Columns.Add("EmailHeader", typeof(string)); foreach (Item item in email.EmailList) { dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body); GridView1.DataSource = dt; GridView1.DataBind(); }
<pre> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowCommand="GridView1_RowCommand" Height="423px"> <Columns> <asp:BoundField DataField="DateCreated" HeaderText="Date and Time" /> <asp:TemplateField HeaderText="Receiver"> <ItemTemplate> <asp:LinkButton runat="server" CommandArgument='<%# Eval("Sender") %>' Text='<%# Eval("Sender") %>'></asp:LinkButton> <%--OnClientClick="document.getElementById('id01').style.display='block'; return false"--%> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Subject" HeaderText="Email Error" /> <asp:TemplateField HeaderText="Email Body"> <ItemTemplate> <asp:Button ID="txtItemBody" runat="server" Text='<%# Eval("EmailHeader") %>' Width="100px" Enabled="false"/> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="View Email "> <ItemTemplate> <asp:Button runat="server" CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" Text="View Email" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /> <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" /> <RowStyle BackColor="whitesmoke" ForeColor="#0a0014" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#0a0014" /> <SortedAscendingCellStyle BackColor="#FEFCEB" /> <SortedAscendingHeaderStyle BackColor="#AF0101" /> <SortedDescendingCellStyle BackColor="#F6F0C0" /> <SortedDescendingHeaderStyle BackColor="#7E0000" /> </asp:GridView>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)