c# - Image Control in Datagrid ASP.Net -
here requirements. database contain few fields along image data bytes. have webpage can filter data few filters , show images in grid view along data.
i wrote code below, other data showing fine in webpage images showing blank. in debug mode verified showing bytes of information image. not receiving error messages well. confused went wrong code.
any please?screenshot of webpage
my class:
public class expense { public string id { get; set; } public datetime starttimestamp { get; set; } public double expenseamt { get; set; } public byte[] photo { get; set; } }
my button click event along method:
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 expense 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; }
my gridview code in aspx file:
<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")) %>'> </asp:image> </itemtemplate> </asp:templatefield> </columns>
your model property mismatched:
imageurl ='<%# "data:image/jpg;base64," + convert.tobase64string((byte[])eval("photo")) %>'
Comments
Post a Comment