public class Expense { public string ID { get; set; } public DateTime StartTimeStamp { get; set; } public double ExpenseAmt { get; set; } public byte[] Photo { get; set; } }
protected void Button1_Click(object sender, EventArgs e) { List<expense> exps = getSQLData(); GridViewImage.DataSource = exps; GridViewImage.DataBind(); } public List<expense> getSQLData() { List<expense> Expenses = new List<expense>(); string cs = ConfigurationManager.ConnectionStrings["test"].ConnectionString; using (SqlConnection conn = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("Select ID, Start_Timestamp, Expense_Amt, Receipt_Photo from EXPENSE where id='testing'", conn); conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Expense exp = new Expense(); exp.ID = rdr[0].ToString(); exp.StartTimeStamp = Convert.ToDateTime(rdr[1].ToString()); exp.ExpenseAmt = Convert.ToDouble(rdr[2].ToString()); exp.Photo = (byte[])rdr[3]; Expenses.Add(exp); } } return Expenses; }
<asp:GridView ID="GridViewImage" runat="server" AutoGenerateColumns="false"> <columns> <asp:BoundField DataField="ID" HeaderText="EnterpriseID" /> <asp:BoundField DataField="StartTimeStamp" HeaderText="StartTimeStamp" /> <asp:BoundField DataField="ExpenseAmt" HeaderText="ExpenseAmt" /> <asp:TemplateField HeaderText="Photo"> <itemtemplate> <asp:Image ID="ReceiptImage" runat="server" Height="500px" Width="500px" ImageUrl ='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Photo")) %>'> </itemtemplate>