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
6 2936
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
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
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
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
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. -
Protected Sub grdResult_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResult.RowDataBound
-
If e.Row.RowType = DataControlRowType.DataRow Then
-
If e.Row.RowIndex = 0 Then
-
Dim drv As DataRowView = e.Row.DataItem
-
For intCellCnt = 1 To e.Row.Cells.Count - 1
-
Dim img As New Image
-
-
img.Width = Unit.Pixel(80)
-
img.Height = Unit.Pixel(80)
-
-
If intCellCnt = 1 Then img.BorderColor = Drawing.Color.Red
-
img.ImageUrl = "~/imgs/" & drv.Item(2).ToString
-
e.Row.Cells(intCellCnt).Text = ""
-
e.Row.Cells(intCellCnt).Controls.Add(img)
-
Next
-
End If
-
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
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. -
Protected Sub grdResult_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResult.RowDataBound
-
If e.Row.RowType = DataControlRowType.DataRow Then
-
If e.Row.RowIndex = 0 Then
-
Dim drv As DataRowView = e.Row.DataItem
-
For intCellCnt = 1 To e.Row.Cells.Count - 1
-
Dim img As New Image
-
-
img.Width = Unit.Pixel(80)
-
img.Height = Unit.Pixel(80)
-
-
If intCellCnt = 1 Then img.BorderColor = Drawing.Color.Red
-
img.ImageUrl = "~/imgs/" & drv.Item(2).ToString
-
e.Row.Cells(intCellCnt).Text = ""
-
e.Row.Cells(intCellCnt).Controls.Add(img)
-
Next
-
End If
-
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 -
If e.Row.RowType = DataControlRowType.DataRow
Should check for DataControlRowT ype.Header instead of DataControlRowT ype.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)...accor ding 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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. Everyone
wants to do a java confirmation box when a user clicks the delete button.
Fair enough, basic user design rules state that you should always confirm a
delete action. There is also a consensus that the best way to do this is a
template...
|
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 prefer to encapsulate all your DML in SPs ? Is it possible
to config the SQLDataSource with SPs ? If not, is there an alternative to
MS's preferred method for config'ing a GridView ?
|
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 GridView.Visible = True.
I press HIDE and the GridView disappears as expected.
After it I press SHOW and the GridView doesn't show.
|
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
|
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 page life cycle.
In this example the event fires twice when a) GridView EnableViewState=False
and any image type control in the <columns/> element. When either
EnableViewState is set to true or the image button is removed, the event
fires once....
| |
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 OleDbParameterCollection" whenI try to write a new record.
Delete and Modify work fine its just the add record function causes the
error.
|
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 footer template has an commandbutton with the commandname set to
'Insert'.
Both buttons cause postback, however the RowCommand event does not fire.
How can I get the rowcommand to fire?
|
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 columns : EmpID, Emp Name, Password, Emp Type.
Now when i remove the value EmpID, the gridview does not update. it just reloads when i hit update but no changes are made.
On the other hand say i make Emp Type as Read only, when i update .. the...
|
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.
I need the ability to insert new rows (which is easily done with
DataTable.Rows.Add(newRow) and rebinding) and then present a row with
different TemplateFields for those rows (I need multiple rows in this
insert state).
|
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, CrtdUser and Date
And Edit and Delete buttons
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |