displaying image in website from a table field which contains image url
-
hi i am designing a desktop application and a website. i have write the following code in desktop application but facing difficulty to do the same task in website.i am using grid to display data. in desktop application the Event "GridView1_CellClick" exist but in website i dont find it, can anyone tell me what changes to do with the follwing code to apply it in website searchgrid.CurrentRow.Cells[0].Value; Image1.Image = Image.FromFile(path); protected void Page_Load(object sender, EventArgs e) { String strConnection; strConnection = "server=localhost;User ID=sa;Password=sasa;database=rescue15"; SqlConnection conn = new SqlConnection(strConnection); conn.Open(); string s = " SELECT cr_pic FROM criminal WHERE cr_id = " + searchgrid.CurrentRow.Cells[0].Value; SqlCommand com1 = new SqlCommand(s, conn); SqlDataReader dr1 = com1.ExecuteReader(); if (dr1.Read()) { string path = dr1.GetValue(0).ToString(); Image1.Image = Image.FromFile(path); } dr1.Close(); } } i am using ASP.Net with C# and SQL Server2005
-
hi i am designing a desktop application and a website. i have write the following code in desktop application but facing difficulty to do the same task in website.i am using grid to display data. in desktop application the Event "GridView1_CellClick" exist but in website i dont find it, can anyone tell me what changes to do with the follwing code to apply it in website searchgrid.CurrentRow.Cells[0].Value; Image1.Image = Image.FromFile(path); protected void Page_Load(object sender, EventArgs e) { String strConnection; strConnection = "server=localhost;User ID=sa;Password=sasa;database=rescue15"; SqlConnection conn = new SqlConnection(strConnection); conn.Open(); string s = " SELECT cr_pic FROM criminal WHERE cr_id = " + searchgrid.CurrentRow.Cells[0].Value; SqlCommand com1 = new SqlCommand(s, conn); SqlDataReader dr1 = com1.ExecuteReader(); if (dr1.Read()) { string path = dr1.GetValue(0).ToString(); Image1.Image = Image.FromFile(path); } dr1.Close(); } } i am using ASP.Net with C# and SQL Server2005
mavii wrote:
Image1.Image = Image.FromFile(path);
This is a waste of time, it creates an image on the server. Generate an img tag which has a src attribute with the server path ( so not the file path, but the path as a URL that a browser can see )
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
mavii wrote:
Image1.Image = Image.FromFile(path);
This is a waste of time, it creates an image on the server. Generate an img tag which has a src attribute with the server path ( so not the file path, but the path as a URL that a browser can see )
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
actually i want to display the image of person according to his ID in the table, so in table i have saved the url, as i have used grid, when one clicks on the Grid, the ID in the first column of the grid is picked and image URL of that ID is taken from table which is diplayed in the picturebox.and i hv not any clear idea of server path, will u plz explain it?
-
actually i want to display the image of person according to his ID in the table, so in table i have saved the url, as i have used grid, when one clicks on the Grid, the ID in the first column of the grid is picked and image URL of that ID is taken from table which is diplayed in the picturebox.and i hv not any clear idea of server path, will u plz explain it?
If your ASP.NET app can see the file, then it must be within the web application. Sending c:\inetpub\MyApp\images\cgraus.jpg means nothing to the client. \images\cgraus/jpg will work fine, it's a path from the web root.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )