asp.net - How to bind imageurl to its imageId stored in database? -


i have uploaded image , store folder in asp.net , stored description in database photo table contains following column

productphoto column name data type   constraint photoid     int         primary key,auto increment photoname   varchar(100)     extname     varchar(100)     phototype   varchar(100)     photosize   int  productid   int         foreign key product info 

and stored image in folder named "upload"

and in gridview in have bound columns database have taken image in item template , and bind imageurl using code

 <asp:gridview id="gridview" autogeneratecolumns="false" runat="server" style="margin-left: 0px" allowpaging="true" allowsorting="true" cellpadding="3" height="238px"  backcolor="#deba84" bordercolor="#deba84" borderstyle="solid" borderwidth="1px" cellspacing="2">     <columns>         <asp:boundfield headertext="photo id" datafield="photoid" />         <asp:boundfield headertext="photo name" datafield="photoname" />         <asp:boundfield headertext="extention name" datafield="extname" />         <asp:boundfield headertext="photo type" datafield="phototype" />         <asp:boundfield headertext="photo size" datafield="photosize" />         <asp:boundfield headertext="product id" datafield="productid" />         <asp:templatefield headertext="product image">             <itemtemplate>                 <asp:image id="productimg"  height="108px"  imageurl="~/upload/" width="98px" runat="server"/>                 </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="delete record">             <itemtemplate>                 <asp:button id="delete" onclientclick="return confirm('are sure delete record?')" text="delete record" commandname="del" commandargument='<%# eval("photoid") %>' runat="server" />             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="edit  record">             <itemtemplate>                 <asp:button id="update"  commandname="upd" text="edit record" commandargument='<%# eval("photoid") %>' runat="server" />             </itemtemplate>         </asp:templatefield>     </columns>      <footerstyle backcolor="#f7dfb5" forecolor="#8c4510" />      <headerstyle backcolor="#a55129" font-bold="true" forecolor="white" />      <pagerstyle forecolor="#8c4510" horizontalalign="center" />      <rowstyle backcolor="#fff7e7" forecolor="#8c4510" />      <selectedrowstyle backcolor="#738a9c" font-bold="true" forecolor="white" />      <sortedascendingcellstyle backcolor="#fff1d4" />      <sortedascendingheaderstyle backcolor="#b95c30" />      <sorteddescendingcellstyle backcolor="#f1e5ce" />      <sorteddescendingheaderstyle backcolor="#93451f" />     </asp:gridview> 

and upload image have used code

protected void insert_click(object sender, eventargs e) { try {

    if (photoupload.hasfile)     {         productphoto prdctphoto = new productphoto();         prdctphoto.photoname = photoupload.filename;         prdctphoto.photosize = photoupload.postedfile.contentlength;         prdctphoto.phototype = photoupload.postedfile.contenttype;         prdctphoto.extname = prdctphoto.photoname.substring(prdctphoto.photoname.lastindexof(".") + 1);         prdctphoto.productid = int.parse(ddlproductname.selectedvalue);         //response.write(data.extname);         int ans = new insertaction().insertdata(prdctphoto);         if (ans != 0)         {             string path = server.mappath("~/upload/") + ans.tostring() + "." + prdctphoto.extname;             photoupload.saveas(path);             lblmsg.text=" file uploaded ";         }          else         {             lblmsg.text="please check fields";         }      }  } catch (exception ex) {     response.write(ex.message); } 

}

can please try below code snippet?

imageurl='<%# "~/upload/" +eval("photoname").tostring().trim()+"." + eval("extname").tostring().trim()  %>' 

or

imageurl='<%#  request.url.scheme + system.uri.schemedelimiter + request.url.host + (request.url.isdefaultport ? "" : ":" + request.url.port) + "/upload/" +eval("photoname")+"." + eval("extname")  %>' 

let me know if not working.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -