Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind imageurl to its imageId stored in database?
    text
    copied!<p>I have uploaded a image and store it into a folder in asp.net and stored its description in database my Photo table contains following column</p> <pre><code>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 with product info </code></pre> <p>and stored image in folder named "upload"</p> <p>And In a gridview in which i have bound all the columns to the database i have taken a image in a item template and and bind its imageurl using this code </p> <pre><code> &lt;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"&gt; &lt;Columns&gt; &lt;asp:BoundField HeaderText="Photo ID" DataField="PhotoID" /&gt; &lt;asp:BoundField HeaderText="Photo Name" DataField="PhotoName" /&gt; &lt;asp:BoundField HeaderText="Extention Name" DataField="ExtName" /&gt; &lt;asp:BoundField HeaderText="Photo Type" DataField="PhotoType" /&gt; &lt;asp:BoundField HeaderText="Photo Size" DataField="PhotoSize" /&gt; &lt;asp:BoundField HeaderText="Product ID" DataField="ProductID" /&gt; &lt;asp:TemplateField HeaderText="Product Image"&gt; &lt;ItemTemplate&gt; &lt;asp:Image ID="productimg" Height="108px" ImageUrl="~/upload/" Width="98px" runat="server"/&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Delete Record"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="delete" OnClientClick="return confirm('Are You Sure To Delete The Record?')" Text="Delete This Record" CommandName="del" CommandArgument='&lt;%# Eval("PhotoID") %&gt;' runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Edit Record"&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="update" CommandName="upd" Text="Edit this Record" CommandArgument='&lt;%# Eval("PhotoID") %&gt;' runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /&gt; &lt;HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /&gt; &lt;RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /&gt; &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /&gt; &lt;SortedAscendingCellStyle BackColor="#FFF1D4" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#B95C30" /&gt; &lt;SortedDescendingCellStyle BackColor="#F1E5CE" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#93451F" /&gt; &lt;/asp:GridView&gt; </code></pre> <p>and to upload the image i have used this code </p> <p>protected void Insert_Click(object sender, EventArgs e) { try {</p> <pre><code> 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 is Uploaded "; } else { lblmsg.Text="Please check all the fields"; } } } catch (Exception ex) { Response.Write(ex.Message); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload