473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView - insert image on run time

58 New Member
Hi,
I have a gridview and want to put image on each columns's top(first row). How can I do that? Please give some idea.
thks
Mar 12 '08 #1
6 2928
nateraaaa
663 Recognized Expert Contributor
Hi,
I have a gridview and want to put image on each columns's top(first row). How can I do that? Please give some idea.
thks
What image are you wanting to add to your gridview header columns? Are you wanting to add an image that will show the direction the column is sorted?

Nathan
Mar 13 '08 #2
Garima12
58 New Member
No, every column is showing the description of properties. I want to display the picture of property and that will be decided on run time that which picture should be called according to records fetched from the database.

What image are you wanting to add to your gridview header columns? Are you wanting to add an image that will show the direction the column is sorted?

Nathan
Mar 17 '08 #3
nateraaaa
663 Recognized Expert Contributor
No, every column is showing the description of properties. I want to display the picture of property and that will be decided on run time that which picture should be called according to records fetched from the database.
I don't understand what you are trying to do. Are you saying you have a gridview full of images? Or are you trying to show an image in the header of a gridview column based on a row column value populated from your database? If you are able to attach a screenshot of what you would like your page to look like that would be great.

Nathan
Mar 17 '08 #4
Frinavale
9,735 Recognized Expert Moderator Expert
No, every column is showing the description of properties. I want to display the picture of property and that will be decided on run time that which picture should be called according to records fetched from the database.
You are going to have to use a TemplateColumn to do this.
See this msdn article for quick instructions.

If you require more assistance after reading through that article, get back to us.

-Frinny
Mar 17 '08 #5
Garima12
58 New Member
thks for the response of both of you.

on button click I am writing code to execute stored procedure to fetch the data from database and it is fetching and filling the gridview correctly. Now I want to add a photo on the top row of each column in gridview. The stored procedure is also fetching the name of image file from the databse.

I am writing following code to get the image displayed, but this is not happening.
Expand|Select|Wrap|Line Numbers
  1. Protected Sub grdResult_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResult.RowDataBound
  2.         If e.Row.RowType = DataControlRowType.DataRow Then
  3.             If e.Row.RowIndex = 0 Then
  4.                 Dim drv As DataRowView = e.Row.DataItem
  5.                 For intCellCnt = 1 To e.Row.Cells.Count - 1
  6.                     Dim img As New Image
  7.  
  8.                     img.Width = Unit.Pixel(80)
  9.                     img.Height = Unit.Pixel(80)
  10.  
  11.                     If intCellCnt = 1 Then img.BorderColor = Drawing.Color.Red
  12.                                  img.ImageUrl = "~/imgs/" & drv.Item(2).ToString
  13.                                  e.Row.Cells(intCellCnt).Text = ""
  14.                     e.Row.Cells(intCellCnt).Controls.Add(img)
  15.                 Next
  16.             End If
  17.  
when I see the properties of the image which is not being displayed, I found it is going till folder imgs, that's it.drv.item(2) is null. I think that's why image is not being displayed.

Please suggest some solution.
Thanks
Mar 18 '08 #6
Frinavale
9,735 Recognized Expert Moderator Expert
thks for the response of both of you.

on button click I am writing code to execute stored procedure to fetch the data from database and it is fetching and filling the gridview correctly. Now I want to add a photo on the top row of each column in gridview. The stored procedure is also fetching the name of image file from the databse.

I am writing following code to get the image displayed, but this is not happening.
Expand|Select|Wrap|Line Numbers
  1. Protected Sub grdResult_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResult.RowDataBound
  2.         If e.Row.RowType = DataControlRowType.DataRow Then
  3.             If e.Row.RowIndex = 0 Then
  4.                 Dim drv As DataRowView = e.Row.DataItem
  5.                 For intCellCnt = 1 To e.Row.Cells.Count - 1
  6.                     Dim img As New Image
  7.  
  8.                     img.Width = Unit.Pixel(80)
  9.                     img.Height = Unit.Pixel(80)
  10.  
  11.                     If intCellCnt = 1 Then img.BorderColor = Drawing.Color.Red
  12.                                  img.ImageUrl = "~/imgs/" & drv.Item(2).ToString
  13.                                  e.Row.Cells(intCellCnt).Text = ""
  14.                     e.Row.Cells(intCellCnt).Controls.Add(img)
  15.                 Next
  16.             End If
  17.  
when I see the properties of the image which is not being displayed, I found it is going till folder imgs, that's it.drv.item(2) is null. I think that's why image is not being displayed.

Please suggest some solution.
Thanks
Are simply trying to display images in the Row Header?
If so, your line
Expand|Select|Wrap|Line Numbers
  1. If e.Row.RowType = DataControlRowType.DataRow 
Should check for DataControlRowType.Header instead of DataControlRowType.DataRow....only when you are on the Header should you be adding images.

Also, where are your images located?
They have to be some place that is accessible to the web page...in other words they have to be on your web server (in the wwwroot folder)...according to you they are in your application's root in a folder named "imgs". Are they there?

If this is the case why are you even storing the names of the files in the database? Why not just use the images as such?

In the future could you please post your code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

-Moderator Frinny
Mar 18 '08 #7

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

Similar topics

3
13725
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
5
1415
by: John A Grandy | last post by:
It looks like MS wants you to use config a SQLDataSource , hand coding the SELECT, INSERT, UPDATE, DELETE SQL , and then assigning GridView.DataSourceID = SQLDataSource ... But what if you...
1
9331
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
10
5281
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
9
24759
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
0
3546
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
13
41953
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The...
3
2054
by: dhaneshrs | last post by:
I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only. Say i have a table Employee with the following...
2
3235
by: DC | last post by:
Hi, I am using a GridView to present data in a DataTable, which I store only in ViewState and when the user hits the "OK" button the rows in the DataTable will be used to execute transactions. ...
11
4053
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
0
7307
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
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
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,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.