List Info

Thread: RE: Error displaying images in gridview




RE: Error displaying images in gridview
country flaguser name
United States
2008-05-01 11:55:39
It looks like you're not setting the MIME Type of the page that's binarywriting out the jpg file.


Date: Thu, 1 May 2008 20:52:24 +0530
From: mishradipakgmail.com
To: aspnet-databasesaspadvice.com
Subject: [aspnet-databases] RE: Error displaying images in gridview


Dear Tim,Rafeeq
This is the error i am getting.......
Thanks for the help.
 
The XML page cannot be displayed

Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


An invalid character was found in text content. Error processing resource 'http://localhost:1277/fmgerp/preorder/imgdisp4.a...





On Wed, Apr 30, 2008 at 9:36 PM, dipak mishra < mishradipakgmail.com">mishradipakgmail.com> wrote:
Yes I did,
I will copy the error tomorrow&nbsp; and will post it here.
Thanks in advance
Regards


 
On Wed, Apr 30, 2008 at 5:25 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
Dipak, did you add the code in 'Catch'&nbsp;to write out an exception to a label control?

> Date: Tue, 29 Apr 2008 18:12:30 +0530

> From: kpmrafeeqgmail.com">kpmrafeeqgmail.com
> Subject: [aspnet-databases] RE: Error displaying images in gridview
&gt; To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
>
> Hi Dipak,
>;
> Just a thought, Try if you have any problem on connecting to the database
&gt; server from production instance, as it working on development instance even
> remotely, Just have a look if any issue with connection from production
> instance.
>
> *Regards,
> Rafeeq
>; Keralam.*
>
> On Tue, Apr 29, 2008 at 5:57 PM, dipak mishra < mishradipakgmail.com">mishradipakgmail.com> wrote:
>;
> > Dear Tim, Rafeeq,
&gt; > I tried the code but again its not showing Images in Grid View.
> > I dont know wats the prob with it.
> > It Shows images on my development machine but not on system.
&gt; > My payment is stuck bcos of this error.Since on developments machine it
> > works well .... while on client side it sometimes stops showing the
> > image.Also same data base works well on our system.
&gt; >
> > Need Help.Dont know wat to do..since no error on develpmnt system.
&gt; >
> > Regards
&gt; >
> >
> >
> > On Wed, Apr 23, 2008 at 7:27 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
>; >
> > > 1. Maybe you're supressing an exception. write it out to a label
> > > control.
&gt; > > 2. try setting the response.contenttype before you response.binarywrite
> > > the image bits.
> > > *Do While** (rdimg.Read()) *
> > > * Response.ClearHeaders()*
> > > * Response.ClearContent()*
> > > * Response.ContentType = "image/jpg"*
> > > Response.BinaryWrite(rdimg.Item("sampimg"))
> > >
> > > Loop
> > >
> > > Incidently, you should add a 'Finally' where you close the connection.
> > > Finally always runs regardless of an exception
> > >
> > > sub page_load(...)
> > > Me.lblMessage.Text = ""
> > > end sub
> > >
> > > function theFunction
> > >
> > >
> > > dim con as new SqlConnection()
> > > Try
> > > con.connectionstring =
> > > ConfigurationManager.ConnectionStrings("connectionstring").connectionstring
> > > .......
&gt; > >
> > > Catch ex As Exception
> > > Me.lblMessage.Text = ex.Message 'View an exception
> > > Finally
&gt; > > If con.State <> ConnectionState.Closed() Then con.Close()
> > > End Try
> > >
> > >
> > > Tim
> > >
> > > ------------------------------
&gt; > > Date: Wed, 23 Apr 2008 10:36:49 +0530
> > >
> > > From: mishradipakgmail.com">mishradipakgmail.com
> > > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > Subject: [aspnet-databases] RE: Error displaying images in gridview
&gt; > >
> > > Dear Tim
> > > here is the code............ for grid view...............SampImg is the
> > > name of the column to display image which has been converted to templte
&gt; > > column ..........formaturl is the function used to pass the sno which is
> > > identity and primary key.
> > >
> > > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
> > > CellPadding="4"
> > > DataKeyNames="snoart" DataSourceID="SqlDataSource4" ForeColor="#333333"
&gt; > > GridLines="None" AllowPaging="True" AllowSorting="True"&gt;
> > > <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
> > > <Columns>
> > > <asp:CommandField ShowSelectButton="True" />
> > > <asp:BoundField DataField="snoart" HeaderText="SNoArt" InsertVisible
> > > ="False" ReadOnly="True"
> > > SortExpression="snoart" />
> > > <asp:BoundField DataField="sampname" HeaderText="SampName"
> > > SortExpression="sampname" />
> > > <asp:BoundField DataField="artdesign" HeaderText="ArtDesign"
> > > SortExpression="artdesign" />
> > > <asp:TemplateField HeaderText="SampImg" SortExpression="sampimg">
>; > > <EditItemTemplate&gt;
> > > <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sampimg") %>
> > > '></asp:TextBox>
> > > </EditItemTemplate>
> > > <ItemTemplate>
> > > <asp:Image ID="Image1" width="75" Height="75" runat="server" ImageUrl='<%#
> > > formaturl(databinder.Eval(container.dataitem,("snoart"))) %>' />
> > > </ItemTemplate>
> > > </asp:TemplateField>
> > > </Columns>
> > > <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
> > > <EditRowStyle BackColor="#999999" />
> > > <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor
> > > ="#333333" />
> > > <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign
> > > ="Center" />
> > > <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
> > > <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
> > > </asp:GridView>
> > >
> > >
> > >
> > >
> > > then there is this format url function in code behind page:--
&gt; > >
> > >
> > > *Function formaturl(ByVal strarguement) As String*
&gt; > > *Return ("imgdisp1.aspx?id="** & strarguement)*
> > > *End Function* **
> > > **
> > > *this function passes the snoart as string argument to page imgdisp1*
> > > *coding for which is:---*
&gt; > > **
> > > *
> > > Protected Sub Page_Load(ByVal sender As Object, ByVal e AsSystem.EventArgs)
&gt; > > Handles Me.Load
&gt; > > Try
> > > Dim strimageid As String = Request.QueryString("id")
> > > Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings(
> > > "erpfmgConnectionString").ConnectionString)
> > > Dim cmd3 As SqlCommand conn.Open()
> > > cmd3 =
> > > New SqlCommand("select * from catalogmast where snoart=" & strimageid,
> > > conn)
> > > 'cmd3 = New SqlCommand("select * from photos", conn)
> > > Dim rdimg As SqlDataReader rdimg = cmd3.ExecuteReader
&gt; > >
> > > Do While (rdimg.Read()) Response.BinaryWrite(rdimg.Item(
> > > "sampimg"))
> > > Loop conn.Close()
> > >
> > > Catch ex As Exception
> > > End Try
> > >
> > >
> > > End Sub
> > > *this is the coding i have used the problem is when i make changes and
> > > updates the virtual directory with new changes then it stops showing image
> > > and after 1-2 days it starts showing image. Also in between it stops showing
&gt; > > image for articles which it used to show. Note:--- All the articles
&gt; > > have image uploaded and saved...so there is no question of Null Values...
> > > below is the code i used to save image to database:---
> > >
> > > If
> > > FileUpload1.HasFile Then
> > > If FileUpload1.PostedFile.ContentType <> "image/pjpeg" AndFileUpload1.PostedFile.ContentType <>
&gt; > > "image/gif" And FileUpload1.PostedFile.ContentType <> "image/bmp" AndFileUpload1.PostedFile.ContentType <>
&gt; > > "image/jpeg" Then lblmsg.Text =
> > > "Select Image File Only"
> > > Exit Sub
> > > End If
> > >
> > > Dim reader As IO.BinaryReader = NewIO.BinaryReader(FileUpload1.PostedFile.InputStream)
> > > Dim image() As Byte =
> > > reader.ReadBytes(FileUpload1.PostedFile.ContentLength)
> > > Dim insertSql As String = "INSERT INTO catalogmast
> > > (sampname,sampdesc,sampimg,arttype,artdesign,buyfrm,buydept) VALUES
>; > > (samp,desc,Photo1,arttype,artdesign,buyfrm,buydept)" cmd2 =
> > > New SqlCommand(insertSql, conn) cmd2.Parameters.Add(
> > > "samp", SqlDbType.NVarChar, 50) cmd2.Parameters(
> > > "samp").Value = Trim(txtname.Text) cmd2.Parameters.Add(
> > > "desc", SqlDbType.NVarChar, 200) cmd2.Parameters(
> > > "desc").Value = Trim(txtdesc.Text)
&gt; > > cmd2.Parameters.Add(
> > > "Photo1", SqlDbType.Image) cmd2.Parameters(
> > > "Photo1").Value = image cmd2.Parameters.AddWithValue(
&gt; > > "arttype", DropDownList2.SelectedItem.Text)
> > > cmd2.Parameters.AddWithValue(
&gt; > > "artdesign", DropDownList4.SelectedItem.Text)
> > > cmd2.Parameters.AddWithValue(
&gt; > > "buyfrm", ddbuyer.SelectedItem.Text) cmd2.Parameters.AddWithValue(
&gt; > > "buydept", dddept.SelectedItem.Text) cmd2.ExecuteNonQuery()
> > >
> > > end if
> > > conn.Close()
> > > lblmsg.Text =
> > > "Sample Data Saved Successfully" the above coding is in transaction with
> > > one more query and with try catch.......
> > > Hope i have made problem clear now.....
&gt; > > Waiting for reply.................
> > > Regards
&gt; > >
> > > Dipak
> > >
> > >
> > > On Tue, Apr 22, 2008 at 5:41 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
>; > >
> > > - can you post the code/html for the grid?
> > > - did you check that the field is not null on the server?
&gt; > > - are you using a page/handler to write the bits back to the page-image?
> > > - are you setting the correct mime type for the image output?
&gt; > > - how are you retrieving the image?
>; > >
> > >
> > >
> > >
> > > ------------------------------
&gt; > > Date: Tue, 22 Apr 2008 12:42:11 +0530
> > >
> > > From: mishradipakgmail.com">mishradipakgmail.com
> > > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > Subject: [aspnet-databases] RE: Error displaying images in gridview
&gt; > >
> > > Tim,
> > > It shows image individually always... not in grid view.... while
> > > sometimes it shows image even in grid view.
> > > Regards
&gt; > > Surendra
&gt; > >
> > > On Mon, Apr 21, 2008 at 5:41 AM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
>; > >
> > > Well, not knowing your app, the only things that come to mind are that
> > > the image field in the database is null or the url from the page that is
> > > creating the web image (<img src='fetchImage.aspx?id=123'> ) is perhaps to
> > > another domain and getting shut down by security on the server. Other than
> > > that, can you post the code that is retrieving the image?
>; > >
> > > ------------------------------
&gt; > > Date: Mon, 21 Apr 2008 00:35:53 +0530
> > > From: mishradipakgmail.com">mishradipakgmail.com
> > > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > Subject: [aspnet-databases] RE: Error displaying images in gridview
&gt; > >
> > > Also the link http://msdn2.microsoft.com/en-us/library/aa479350.aspx
> > > displays picture from url stored in database not from image itself stored in
> > > database.
> > > while the 2nd link shows how to store image to database and read image
> > > from database singly.. but the problem i am facing is that sometimes its
> > > not displayed in gridview wherein i have converted a column to template
&gt; > > insert a image box into it and pass serial no as primary key to other page
> > > (where i am reading image and displaying it by response.write (bibary
&gt; > > thing) whose url i am setting as url for image control.
&gt; > > So may be now my problem is clearer.
&gt; > > Regards
&gt; > > Dipak
> > > Thanks in Advance
&gt; > >
> > > On Mon, Apr 21, 2008 at 12:26 AM, dipak mishra < mishradipakgmail.com">mishradipakgmail.com>
> > > wrote:
>; > >
> > > Thanks TIM, Rafeeq , and others for help,
> > > I think i have not made myself clear i am getting the images to be
> > > displayed ... storing or displaying image is anot an issue.... but the
> > > problem is that at my clients place it sometimes stops showing the images in
> > > grid view.... while it shows on image box individually..
> > > Regards
&gt; > > Dipak
> > >
> > > On Fri, Apr 18, 2008 at 6:17 PM, Rafeeq . < kpmrafeeqgmail.com">kpmrafeeqgmail.com> wrote:
>; > >
> > > Yes Tim,
> > >
> > > I think he can apply the same concept to display the image.
>; > >
> > > --
> > > Regards,
&gt; > > >Rafeeq
> > > >Keralam
> > >
> > > On Fri, Apr 18, 2008 at 5:46 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
>; > >
> > > > Rafeeq, this is old ADO. I think Dipak wants ADO.Net.
&gt; > > >
> > > > > Date: Fri, 18 Apr 2008 13:06:43 +0530
> > > > > From: kpmrafeeqgmail.com">kpmrafeeqgmail.com
> > > > > Subject: [aspnet-databases] RE: Error displaying images in gridview
&gt; > > >
> > > > > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > > >
> > > > > Hi Dipak,
>; > > > >
> > > > > Try below method.
&gt; > > > >
> > > > > str = "SELECT image FROM album where id =" & ID
> > > > > rs.Open str, conn
> > > > > if rs.eof then 'No records found
> > > > > Response.End
> > > > > else 'Display the contents
&gt; > > > > Response.ContentType = "image/gif"
> > > > > Response.BinaryWrite(rs("image"))
> > > > > end if
> > > > >
> > > > > You can use red highlighted code in the grid, if you are using
> > > extended
&gt; > > > > grid.
> > > > >
> > > > > As you are storing it as binary format. you need to reload it in
> > > binary,
&gt; > > > > try.. this
> > > > >
> > > > > Happy coding,
&gt; > > > > --
> > > > > With Warm Regards,
&gt; > > > >
> > > > > >Rafeeq
> > > > > >Keralam
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On Fri, Apr 18, 2008 at 12:51 PM, dipak mishra <
> > > mishradipakgmail.com">mishradipakgmail.com>
> > > > > wrote:
>; > > > >
> > > > > > Dear Allen,
>; > > > > > I am storing Image itself in database not the path to it.
> > > > > > How to display that using image field.
>; > > > > > I am not able to do so.
> > > > > > Plz Help
> > > > > >
> > > > > > On 4/18/08, Allen Moon < howlmoonclearwire.net">howlmoonclearwire.net> wrote:
>; > > > > > > Hey there
> > > > > > > In ASP 2.0 there is a ImageField in gridview that you need to
> > > use.
> > > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: dipak mishra [mailto: mishradipakgmail.com">mishradipakgmail.com]
> > > > > > > Sent: Thursday, April 17, 2008 1:15 PM
> > > > > > > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > > > > > Cc: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > > > > > Subject: [aspnet-databases] Error displaying images in gridview
&gt; > > > > > >
> > > > > > > Hi All,
> > > > > > > I am facing a problem on which i would like to have suggestions.
> > > > > > > I have an ERP Application in ASP.net 2.0 with sql 2005 as back
> > > end.
> > > > I am
> > > > > > > storing images in database then i am displaying it on a page and
> > > > giving
>; > > > > > the
> > > > > > > URL of that page in grid view template field which has a image
> > > > control.
&gt; > > > > > > Same thins i have been doing in application developed in asp 1.0
> > > and
> > > > sql
> > > > > > 7.0
> > > > > > > the images are displayed correctly everywhere.
> > > > > > > But in this application in Grid view the same image have stopped
&gt; > > > being
> > > > > > > displayed. Although if i view them individually on other page
> > > they
> > > > are
> > > > > > > displayed correctly.
> > > > > > > The client has genuine sql server.with service pack 2. Same
> > > things
>; > > > are
> > > > > > > working fine on my development machine and similar thing is
> > > running
&gt; > > > fine
> > > > > > in
> > > > > > > asp 1.0 and sql 7.0.
> > > > > > > It was running fine on this clients system too. All of a sudden
>; > > this
> > > > is
> > > > > > not
> > > > > > > displaying image in grid view.
> > > > > > > I have reinstalled sql2005 still same problem.
&gt; > > > > > > The images are saved in sql 2005 this i have checked also the
> > > images
>; > > > are
> > > > > > > displayed correctly individually which proves images are in fact
> > > > saved
> > > > > > > actually.
> > > > > > > Any help will be graetly appreciated since i am stuck
> > > > > > > Regards
&gt; > > > > > > Dipak
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Need SQL Advice? http://sqladvice.com
> > > > > > > Need RegEx Advice? http://regexadvice.com
> > > > > > > Need XML Advice? http://xmladvice.com
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Need SQL Advice? http://sqladvice.com
> > > > > > > Need RegEx Advice? http://regexadvice.com
> > > > > > > Need XML Advice? http://xmladvice.com
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Need SQL Advice? http://sqladvice.com
> > > > > > > Need RegEx Advice? http://regexadvice.com
> > > > > > > Need XML Advice? http://xmladvice.com
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Need SQL Advice? http://sqladvice.com
> > > > > > > Need RegEx Advice? http://regexadvice.com
> > > > > > > Need XML Advice? http://xmladvice.com
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Need SQL Advice? http://sqladvice.com
> > > > > > > Need RegEx Advice? http://regexadvice.com
> > > > > > > Need XML Advice? http://xmladvice.com
> > > > > > >
> > > > > >
> > > > > > Need SQL Advice? http://sqladvice.com
> > > > > > Need RegEx Advice? http://regexadvice.com
> > > > > > Need XML Advice? http://xmladvice.com
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > Need SQL Advice? http://sqladvice.com
> > > > > Need RegEx Advice? http://regexadvice.com
> > > > > Need XML Advice? http://xmladvice.com
> > > >
> > > > ------------------------------
&gt; > > > Pack up or back up–use SkyDrive to transfer files or keep extra
> > > copies. Learn
> > > > how.<
&gt; > > http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008>Need
&gt; > > SQL Advice?
&gt; > > > http://sqladvice.com
> > > > Need RegEx Advice? http://regexadvice.com
> > > > Need XML Advice? http://xmladvice.com
> > > >
> > >
> > >
> > >
> > > --
> > > With Warm Regards,
&gt; > >
> > > >Rafeeq
> > > >Keralam
> > >
> > >
> > >
> > > Need SQL Advice? http://sqladvice.com
> > > Need RegEx Advice? http://regexadvice.com
> > > Need XML Advice? http://xmladvice.com
> > >
> > >
> > >
> > > Need SQL Advice? http://sqladvice.com Need RegEx Advice?
&gt; > > http://regexadvice.com Need XML Advice? http://xmladvice.com
> > >
> > >
> > > ------------------------------
&gt; > > Going green? See the top 12 foods to eat organic.&lt;http://green.msn.com/galleries/photos/photos.aspx?gid=164&ocid=T003MSN51N1653A>
> > > Need SQL Advice? http://sqladvice.com
> > > Need RegEx Advice? http://regexadvice.com
> > > Need XML Advice? http://xmladvice.com
> > >
> > >
> > > Need SQL Advice? http://sqladvice.com Need RegEx Advice?
&gt; > > http://regexadvice.com Need XML Advice? http://xmladvice.com
> > >
> > >
> > > ------------------------------
&gt; > > Back to work after baby– how do you know when you're ready?<http://lifestyle.msn.com/familyandparenting/articleNW.aspx?cp-documentid=5797498&ocid=T067MSN40A0701A>;Need SQL Advice?
&gt; > > http://sqladvice.com
> > > Need RegEx Advice? http://regexadvice.com
> > > Need XML Advice? http://xmladvice.com
> > >
> > >
> > > Need SQL Advice? http://sqladvice.com Need RegEx Advice?
&gt; > > http://regexadvice.com Need XML Advice? http://xmladvice.com
> > >
> > >
> > > ------------------------------
&gt; > > Express yourself wherever you are. Mobilize!&lt;http://www.gowindowslive.com/Mobile/Landing/Messenger/Default.aspx?Locale=en-US?ocid=TAG_APRIL>;Need SQL Advice?
&gt; > > http://sqladvice.com
> > > Need RegEx Advice? http://regexadvice.com
> > > Need XML Advice? http://xmladvice.com
> > >
> >
> > Need SQL Advice? http://sqladvice.com Need RegEx Advice?
&gt; > http://regexadvice.com Need XML Advice? http://xmladvice.com
> >
>
>
>
> Need SQL Advice? http://sqladvice.com
> Need RegEx Advice? http://regexadvice.com
> Need XML Advice? http://xmladvice.com


Back to work after baby– how do you know when you're ready? Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com

Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com


Express yourself wherever you are. Mobilize! Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )