Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii i have been uploaded image using below code its working.Image path is gooing in database and image also storing in folder bt image is not displaying in gridview.How can i do.. using this code plzz edit or modify code for show image in gridview..

SqlConnection con = new SqlConnection("Data Source=DEEPAK-PC\\SQLEXPRESS;Initial Catalog=Imageup;User ID=sa;Password=sasa");
   protected void Page_Load(object sender, EventArgs e)
   {

   }

  protected void Button1_Click(object sender, EventArgs e)
   {
       if (FileUpload1.HasFile)
       {
           String str = FileUpload1.FileName;
           //FileUpload1.PostedFile.SaveAs(Server.MapPath(",") + "~//uploadedimages//" + str);


           string FileName= Path.GetFileName(FileUpload1.FileName);
           FileUpload1.SaveAs(Server.MapPath("~/uploadedimages/")+ FileName);
           string path = "~//Uploads//"+str.ToString();
           con.Open();
           SqlCommand cmd = new SqlCommand("insert into FileUploads1 values('" + TextBox1.Text + "','" + path + "')", con);
           cmd.ExecuteNonQuery();
           con.Close();
           Label1.Text = "Image upload Successfully";
       }
       else
       {
           Label1.Text = "Plz select ur image and upload";
       }
       SqlDataAdapter da = new SqlDataAdapter("select * from FileUploads1", con);
       DataTable dt = new DataTable();
       da.Fill(dt);
       GridView1.DataSource = dt;
       DataBind();



   }
Posted
Comments
JoCodes 8-Jan-14 5:43am    
Check the file path of the image . Use the same path which you are trying to save the image. Can you show the gridview markup code too?
amit1992 8-Jan-14 5:46am    
markup code for gridview..

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None">
<alternatingrowstyle backcolor="White">
<footerstyle backcolor="#990000" font-bold="True" forecolor="White">
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<rowstyle backcolor="#FFFBD6" forecolor="#333333">
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<sortedascendingcellstyle backcolor="#FDF5AC">
<sortedascendingheaderstyle backcolor="#4D0000">
<sorteddescendingcellstyle backcolor="#FCF6C0">
<sorteddescendingheaderstyle backcolor="#820000">
<columns>
<asp:TemplateField HeaderText="uid">
<itemtemplate>
<asp:Label ID="lbl1" runat="server" >


<asp:TemplateField HeaderText="Name">
<itemtemplate>
<asp:Label ID="lbl1" runat="server" >


<asp:TemplateField HeaderText="Image">
<itemtemplate>
<asp:Image ID="img" runat="server" Height="100" Width="100" />



JoCodes 8-Jan-14 5:50am    
set the imageurl property to the imaeg control . Have added a solution . check .
amit1992 8-Jan-14 5:59am    
Where u added a solution plzz post in comment or refer where u added. Thnxx.
amit1992 8-Jan-14 6:11am    
@jocodes i have set the imageurl property nw image is not showing properly.

Use image handler for displaying image in gridview.
Refer :http://stackoverflow.com/questions/19132451/how-to-display-binary-images-into-a-gridview-in-asp-net-using-c[^]

Hope this will help.
 
Share this answer
 
v2
Comments
amit1992 8-Jan-14 5:50am    
@Gitanjali Singh plzz tell without using image handler..
Gitanjali Singh 8-Jan-14 5:55am    
Refer:http://stackoverflow.com/questions/20741343/how-to-display-image-inside-gridview-template-field-without-using-handler-class
hi...
See this link,may its help ful to u.
How to bind images in datalist/gridview[^]
Thank u.
 
Share this answer
 
Refer

http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html[^]

Also , check the paths are same while saving the file and inserted path to DB.

FileUpload1.SaveAs(Server.MapPath("~/uploadedimages/")+ FileName);

and the

"insert into FileUploads1 values('" + TextBox1.Text + "','" + path + "'
should be same .
Hope this helps...
 
Share this answer
 
v2
I m getting Image path in gridview when runs the application. how can show image, not path.
plzz help me..i trie my fulll effort..bt nt success..Thnxx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900