473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

the image is inserted into the db successfully , but cant retrieve it

Hello ladies and gentlemen of the forum. I bear grevious news. I am able to execute the following code which saves an image file to my database without error. I am confident that the image is saved as expected. Yet to my horror I find then when I try to display my image in a gridview it does not appear in the same way Santa Clause does. I am all a tither! Alas and alack! Oh, who will save me?
httphandler (generic handler)>>
Expand|Select|Wrap|Line Numbers
  1. public class Handler : IHttpHandler {
  2.  
  3. public void ProcessRequest (HttpContext context) {
  4. SqlConnection con = new SqlConnection();
  5. con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial Catalog=imagek;Integrated Security=True";
  6.  
  7. con.Open();
  8. SqlCommand command = new SqlCommand("SELECT * from image ", con);
  9. SqlDataReader dr = command.ExecuteReader();
  10. dr.Read();
  11. context.Response.BinaryWrite((Byte[])dr[0]);
  12. //context.Response.ContentType = "text/plain";
  13. //context.Response.Write("Hello World");
  14. con.Close();
  15. context.Response.End();
  16. }
  17.  
  18. public bool IsReusable {
  19. get {
  20. return false;
  21. }
  22. }
  23.  
  24. }
  25. default page>>
i have an uploader control , the image is inserted into the db successfully , but cant retrieve it>>
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using System.Data.SqlClient;
  14. using System.Windows.Forms;
  15. //using System.Web.
  16.  
  17. public partial class _Default : System.Web.UI.Page
  18. {
  19.  
  20. //con.ConnectionString =SqlConnection con = new SqlConnection();
  21.  
  22. public SqlConnection con = new SqlConnection();
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial Catalog=imagek;Integrated Security=True";
  26.  
  27.  
  28.  
  29. }
  30. protected void Button1_Click(object sender, EventArgs e)
  31. {
  32. if (FileUpload1.HasFile)
  33. {
  34.  
  35. con.Open();
  36. byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
  37. HttpPostedFile myimg = FileUpload1.PostedFile;
  38. myimg.InputStream.Read(img, 0, FileUpload1.PostedFile.ContentLength);
  39.  
  40. SqlCommand cmd = new SqlCommand("insert into image values(22,'"+ img +"')",con);
  41.  
  42. cmd.ExecuteNonQuery();
  43.  
  44. con.Close();
  45. }
  46. }
  47. protected void Button2_Click(object sender, EventArgs e)
  48. { DataSet ds = new DataSet();
  49. con.Open();
  50. SqlCommand command = new SqlCommand("SELECT id from image ", con);
  51. // SqlCommand command = new SqlCommand("SELECT imagename,ImageID from [Image]", connection);
  52. SqlDataAdapter daimages = new SqlDataAdapter(command);
  53. DataTable dt = new DataTable();
  54. daimages.Fill(dt);
  55. GridView1.DataSource = dt;
  56. GridView1.DataBind();
  57. GridView1.Attributes.Add("bordercolor", "black");
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. }
  66.  
  67. }
Feb 17 '12 #1
8 4573
Newface
16
Please include a webhandler to display your image in gridview,otherwise i think it is not possible,if possible then do intimate me.for now include a templatefield in your gridview columns like below
Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField>
  2.                             <ItemTemplate>
  3.                                 <img src="~/ShowImage.ashx?FacultyID=<%# Eval(FacultyID) %>" runat="server" width="100" height="50"/>
  4.                             </ItemTemplate>
  5.                         </asp:TemplateField>
  6.  
in load of your aspx.cs
Expand|Select|Wrap|Line Numbers
  1. pID = Request.QueryString["FacultyID"].ToString();
  2. cmd.Parameters.Add(new SqlParameter("@FacultyID", pID));
  3.                     DataTable dt = new DataTable();
  4.                     da.Fill(dt);
  5.                     profileGridView.DataSource = dt;
  6.                     profileGridView.DataBind();
  7.  
and the page where you are redirecting from,in aspx.cs,include;
Expand|Select|Wrap|Line Numbers
  1.  string stext=cmdFacultyID.Text.Trim().ToString();
  2.             Response.Redirect(ResolveUrl("~/FacultyMaster/Faculty Profile.aspx?FacultyID="+stext));
  3.  
Feb 20 '12 #2
PsychoCoder
465 Expert Mod 256MB
Take a look at this, it's in VB.NET but converting it to C# shouldn't be that difficult
Feb 21 '12 #3
Newface
16
Dear PsychoCoder,i am a beginner in this technology and forum so please please excuse my minor mistakes and negligence.
Feb 21 '12 #4
dear newface: even after including the web handler , i am retrieving the whole table in gridview,but the image is not shown as shown in attachment , am i missing some code ?
Attached Images
File Type: jpg Untitled.jpg (24.4 KB, 238 views)
Feb 22 '12 #5
Newface
16
please post your updated code so that could help you further if possible.
Feb 22 '12 #6
here i have included the files of my project , please help me
DEFAULT.ASPX.CS
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.IO;
  13. using System.Xml.Linq;
  14. using System.Data.SqlClient;
  15. using System.Windows.Forms;
  16.  
  17. //using System.Web.
  18.  
  19. public partial class _Default : System.Web.UI.Page
  20. {
  21.  
  22.     //con.ConnectionString =SqlConnection con = new SqlConnection();
  23.  
  24.   public SqlConnection con = new SqlConnection();
  25.     protected void Page_Load(object sender, EventArgs e)
  26.     {
  27.         con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial Catalog=imagek;Integrated Security=True";
  28.  
  29.        //if(!Roles.RoleExists("admin"))
  30.        //{}
  31.  
  32.     }
  33.     protected void Button1_Click(object sender, EventArgs e)
  34.     {
  35.         if (FileUpload1.HasFile)
  36.         {
  37.  
  38.             con.Open();
  39.             byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
  40.             HttpPostedFile myimg = FileUpload1.PostedFile;
  41.             myimg.InputStream.Read(img, 0, FileUpload1.PostedFile.ContentLength);
  42.  
  43.             SqlCommand cmd = new SqlCommand("insert into image values(22,'"+ img +"')",con);
  44.  
  45.             cmd.ExecuteNonQuery();
  46.  
  47.             con.Close();
  48.         }
  49.     }
  50.     protected void Button2_Click(object sender, EventArgs e)
  51.     { DataSet ds = new DataSet();
  52.     con.Open();
  53.     SqlCommand command = new SqlCommand("SELECT id from image ", con);
  54.   //  SqlCommand command = new SqlCommand("SELECT imagename,ImageID from [Image]", connection);
  55.     SqlDataAdapter daimages = new SqlDataAdapter(command);
  56.     DataTable dt = new DataTable();
  57.     daimages.Fill(dt);
  58.     GridView1.DataSource = dt;
  59.     GridView1.DataBind();
  60.     GridView1.Attributes.Add("bordercolor", "black");
  61.  
  62.  
  63.  
  64.     Image img = new Image();
  65.    // ImageMap1.DataSource = ds;
  66.  
  67.  
  68.  
  69.     }
  70.  
  71. }
WEB.CONFIG
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <!-- 
  3.     Note: As an alternative to hand editing this file you can use the 
  4.     web admin tool to configure settings for your application. Use
  5.     the Website->Asp.Net Configuration option in Visual Studio.
  6.     A full list of settings and comments can be found in 
  7.     machine.config.comments usually located in 
  8.     \Windows\Microsoft.Net\Framework\v2.x\Config 
  9. -->
  10.  
  11. <configuration>
  12.     <configSections>
  13.         <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  14.             <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  15.                 <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  16.                 <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  17.                     <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
  18.                     <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  19.                     <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  20.                     <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
  21.                 </sectionGroup>
  22.             </sectionGroup>
  23.         </sectionGroup>
  24.     </configSections>
  25.     <appSettings/>
  26.     <connectionStrings>
  27.   <add name="imagekConnectionString" connectionString="Data Source=home-pc\sqlexpress;Initial Catalog=imagek;Integrated Security=True"
  28.    providerName="System.Data.SqlClient" />
  29.  </connectionStrings>
  30.  
  31.   <!--</roleManager>-->
  32.     <system.web>
  33.         <!-- 
  34.             Set compilation debug="true" to insert debugging 
  35.             symbols into the compiled page. Because this 
  36.             affects performance, set this value to true only 
  37.             during development.
  38.         -->
  39.         <compilation debug="true">
  40.             <assemblies>
  41.                 <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  42.                 <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  43.                 <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  44.                 <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  45.                 <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
  46.         </compilation>
  47.         <!--
  48.             The <authentication> section enables configuration 
  49.             of the security authentication mode used by 
  50.             ASP.NET to identify an incoming user. 
  51.         -->
  52.         <authentication mode="Windows"/>
  53.         <!--
  54.             The <customErrors> section enables configuration 
  55.             of what to do if/when an unhandled error occurs 
  56.             during the execution of a request. Specifically, 
  57.             it enables developers to configure html error pages 
  58.             to be displayed in place of a error stack trace.
  59.  
  60.         <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
  61.             <error statusCode="403" redirect="NoAccess.htm" />
  62.             <error statusCode="404" redirect="FileNotFound.htm" />
  63.         </customErrors>
  64.         -->
  65.         <pages>
  66.             <controls>
  67.                 <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  68.                 <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  69.             </controls>
  70.         </pages>
  71.         <httpHandlers>
  72.             <remove verb="*" path="*.asmx"/>
  73.             <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  74.             <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  75.             <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
  76.         </httpHandlers>
  77.         <httpModules>
  78.             <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  79.         </httpModules>
  80.     </system.web>
  81.     <system.codedom>
  82.         <compilers>
  83.             <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  84.                 <providerOption name="CompilerVersion" value="v3.5"/>
  85.                 <providerOption name="WarnAsError" value="false"/>
  86.             </compiler>
  87.             <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  88.                 <providerOption name="CompilerVersion" value="v3.5"/>
  89.                 <providerOption name="OptionInfer" value="true"/>
  90.                 <providerOption name="WarnAsError" value="false"/>
  91.             </compiler>
  92.         </compilers>
  93.     </system.codedom>
  94.     <!-- 
  95.         The system.webServer section is required for running ASP.NET AJAX under Internet
  96.         Information Services 7.0.  It is not necessary for previous version of IIS.
  97.     -->
  98.     <system.webServer>
  99.         <validation validateIntegratedModeConfiguration="false"/>
  100.         <modules>
  101.             <remove name="ScriptModule"/>
  102.             <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  103.         </modules>
  104.         <handlers>
  105.             <remove name="WebServiceHandlerFactory-Integrated"/>
  106.             <remove name="ScriptHandlerFactory"/>
  107.             <remove name="ScriptHandlerFactoryAppServices"/>
  108.             <remove name="ScriptResource"/>
  109.             <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  110.             <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  111.             <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  112.         </handlers>
  113.     </system.webServer>
  114.     <runtime>
  115.         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  116.             <dependentAssembly>
  117.                 <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
  118.                 <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
  119.             </dependentAssembly>
  120.             <dependentAssembly>
  121.                 <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
  122.                 <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
  123.             </dependentAssembly>
  124.         </assemblyBinding>
  125.     </runtime>
  126. </configuration>
GENERIC HANDLER
Expand|Select|Wrap|Line Numbers
  1. <%@ WebHandler Language="C#" Class="Handler" %>
  2.  
  3. using System;
  4. using System.Web;
  5. using System.Data.SqlClient;
  6.  
  7. public class Handler : IHttpHandler {
  8.  
  9.     public void ProcessRequest (HttpContext context) {
  10.  
  11.         string imageid = context.Request.QueryString["ImID"];
  12.         SqlConnection con = new SqlConnection();
  13.         con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial Catalog=imagek;Integrated Security=True";
  14.  
  15.         con.Open();
  16.         SqlCommand command = new SqlCommand("SELECT imagefile from image ", con);
  17.         SqlDataReader dr = command.ExecuteReader();
  18.         dr.Read();
  19.         context.Response.BinaryWrite((Byte[])dr[0]);
  20.         //context.Response.ContentType = "text/plain";
  21.         //context.Response.Write("Hello World");
  22.         con.Close();
  23.         context.Response.End();
  24.     }
  25.  
  26.     public bool IsReusable {
  27.         get {
  28.             return true ;
  29.         }
  30.     }
  31.  
  32. }
  33. DEFAULT ASPX
  34. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  35.  
  36. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  37.  
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head runat="server">
  40.     <title>Untitled Page</title>
  41. </head>
  42. <body>
  43.     <form id="form1" runat="server">
  44.     <div>
  45.  
  46.     </div>
  47.     <asp:FileUpload ID="FileUpload1" runat="server" />
  48.     <p>
  49.         <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
  50.         <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
  51.     </p>
  52.     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  53.     <Columns>
  54.     <asp:BoundField HeaderText = "Image Name" DataField="id" />
  55. <asp:TemplateField HeaderText="Image">
  56. <ItemTemplate>
  57. <asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?ImID="+ Eval("id") %>' Height="150px" Width="150px"/>
  58. </ItemTemplate>
  59. </asp:TemplateField>
  60. </Columns>
  61.     </asp:GridView>
  62.  
  63.     </form>
  64. </body>
  65. </html>
Feb 23 '12 #7
Newface
16
just minor edit like
in place of
//SqlDataReader dr = command.ExecuteReader();
//dr.Read();
//context.Response.BinaryWrite((Byte[])dr[0]);
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
Expand|Select|Wrap|Line Numbers
  1. byte[] imgContent=(byte[])command.ExecuteScalar();
  2. context.Response.ContentType = "image/jpeg"; 
  3. context.Response.OutputStream.Write(imgContent,0,imgContent.Length); 
  4.  
in your Generic Handler,and in your default aspx,in place of
//<asp:TemplateField HeaderText="Image">
//<ItemTemplate>
//<asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?ImID="+ Eval("id") %>' Height="150px" Width="150px"/>
//</ItemTemplate>
//</asp:TemplateField>

add
Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField>
  2.                                                     <ItemTemplate>
  3.  <img runat="server" src="Handler.ashx?ImID=<%# Eval(ImID) %>" Height="150" Width="150"/>                                                       
  4.  
  5.                                                     </ItemTemplate>
  6.                                                 </asp:TemplateField>
  7.  
  8.  
try doing this and it will get resolved.
Feb 24 '12 #8
Newface
16
is this working for you?,anyway, i have prepared one test file for you as can see below:
Expand|Select|Wrap|Line Numbers
  1. //in Handler.ashx
  2. public void ProcessRequest(HttpContext context)
  3.     {
  4.         string Name = context.Request.QueryString.Get("ProfileName");
  5.         SqlConnection con = clsConnection.GetConnection();
  6.         SqlCommand cmd = new SqlCommand("GetDatah");
  7.         SqlDataReader dr = null;
  8.         cmd.CommandType = CommandType.StoredProcedure;
  9.         cmd.Parameters.Add(new SqlParameter("@profileName", Name));
  10.         cmd.Connection = con;
  11.         con.Open();
  12.         dr =  cmd.ExecuteReader();
  13.         while (dr.Read())
  14.         {
  15.             context.Response.BinaryWrite((byte[])dr[0]);
  16.             //byte[] imgData = (byte[])cmd.ExecuteScalar();
  17.             //context.Response.ContentType = "image/bmp";
  18.             //context.Response.OutputStream.Write(imgData, 0, imgData.Length);
  19.             con.Close();
  20.             context.Response.End();
  21.         }
  22.     }
  23.  
Expand|Select|Wrap|Line Numbers
  1. //in aspx.cs
  2.     protected void cmdShowProfile_Click(object sender, EventArgs e)
  3.     {
  4.         con = clsConnection.GetConnection();
  5.         cmd = new SqlCommand("GetDataAll");
  6.         dt = new DataTable();
  7.         da = new SqlDataAdapter();
  8.         cmd.CommandType = CommandType.StoredProcedure;
  9.         profileName = txtName.Text.Trim();
  10.         //cmd.Parameters.Add(new SqlParameter("@profileName", profileName));
  11.         cmd.Connection = con;
  12.         da.SelectCommand = cmd;
  13.         da.Fill(dt);
  14.         if (dt.Rows.Count > 0)
  15.         {
  16.             GrdvPicture.DataSource = dt;
  17.             GrdvPicture.DataBind();
  18.         }
  19.         else
  20.             GrdvPicture.EmptyDataText = "No record found";
  21.  
  22.     //cmdShowProfile.PostBackUrl = "Default.aspx?ProfileName='"+profileName+"'" ;
  23.         //Response.Redirect("~/Default.aspx?ProfileName="+profileName, true);
  24.     }
  25.     protected void GrdvPicture_RowDataBound(object sender, GridViewRowEventArgs e)
  26.     {
  27.         if (e.Row.RowType == DataControlRowType.DataRow)
  28.         {
  29.             string ProfileName=Convert.ToString(DataBinder.Eval(e.Row.DataItem,"ProfileName"));
  30.             Image img = (Image)e.Row.FindControl("ProfileImage");
  31.  
  32.         }
  33.     }
  34.  
Expand|Select|Wrap|Line Numbers
  1. //in .aspx
  2. <asp:GridView ID="GrdvPicture" runat="server" AutoGenerateColumns="False" 
  3.                                             DataKeyNames="ProfileName" OnRowDataBound="GrdvPicture_RowDataBound">
  4.                                             <Columns>
  5.                                                 <asp:BoundField DataField="ProfileName" HeaderText="Name" />
  6.                                                 <asp:TemplateField HeaderText="Image">
  7.                                                     <ItemTemplate>
  8.                                                         <asp:Image ID="ProfileImage" runat="server" ImageUrl='<%#"Handler.ashx?ProfileName="+Eval("ProfileName") %>' Height="50px" Width="50px"  />
  9.  
  10.                                                     </ItemTemplate>
  11.                                                 </asp:TemplateField>
  12.                                             </Columns>
  13.                                         </asp:GridView>
  14.  
Feb 27 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Leszek | last post by:
Hello, I need to set dynamically height and width attributes of an image control on a WebForm. I know how to read the whole image from the hard-drive and use its height and width properties. I...
6
by: David Bowey | last post by:
Hi There! I'm writing a custom HttpHandler to create watermarks on my PNG images of my website. So typically, a PNG image is linked in an ASPX page as follows... <img src="images/test.png"...
2
by: NATO24 | last post by:
Hello, I am trying to write a sub routine that I can pass a posted (image) file to. That routine will save the original file, then create a thumbnail and save it. When I try to create the image...
2
by: feets | last post by:
OK first time poster, so hello everyone in advance. Right i'm sure this is a simple problem to solve, but I'm just getting the hang of SQL 2000. What I've got is a form where I input the values and...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
3
Raju B
by: Raju B | last post by:
hi friends i had written a code for uploading image.but it showing error like failed to open stream on line 61.please go through my code and suggest me. <?php //include 'include/dbconnect.php';...
1
by: Amit Girish Deshpande | last post by:
Hi all, I have created small Gui application for Bank form. I am using C as Development language along with gtk. i want to store image of every Customer in database. How to insert image into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.