Click here to Skip to main content
14,218,620 members
Rate this:
Please Sign up or sign in to vote.
Hi,

  I want to show one image inside my datatable.
 Am using code,

   dr = dt.newrow();
   dr[0]= <in this row i want to show the image>
  dt.addrow(dr);

How can i do this?


Here am checking some values, For example the value in any cell is greater than 50 the it should show one UP arrow inside that cell.Am checking the value from DB.In .net side am filtering like
if(value>50)
{
dt.rows[]="here i want to show one up arrow"
}
So how can i do that? No need to store the value in DB right?
Posted
Updated 12-Mar-13 21:49pm
v4
Comments
joshrduncan2012 12-Mar-13 10:17am
   
What have you tried in that row you are pointing to that isn't working for you?
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
Am Gayathri 12-Mar-13 10:25am
   
This article shows how to show picture which stored in database,
but here i want to show the picture which i stored in my project folder.
JasonMacD 12-Mar-13 10:29am
   
In real world development you would host the image in a DB then access it. Try adding it to your local sql server express DB and continue with the tutorial if you want, it'll be good experience going through a real world process.
JasonMacD 12-Mar-13 10:30am
   
Btw you mentioned you wanted it dynamically, if it is to be dynamic it would come from the DB.
Am Gayathri 12-Mar-13 10:54am
   
Here am checking some values,
For example the value in any cell is greater than 50 the it should show one UP arrow inside that cell.Am checking the value from DB.In .net side am filtering like
if(value>50)
{
dt.rows[]="here i want to show one up arrow"
}
So how can i do that?
No need to store the value in DB right?
Am Gayathri 13-Mar-13 3:07am
   
i tried this,
dt.rows[]=<img src "path">

But not working
Rate this:
Please Sign up or sign in to vote.

Solution 2

Store image path in database... and take image control in your gridview, when you bind the gridview the bind the image path to the ImageUrl Property of image control, it will show image in gridview.
   
Comments
Am Gayathri 13-Mar-13 3:07am
   
I cant store the image in Database
need to do in other ways
vishal.shimpi 13-Mar-13 7:16am
   
i m suggesting you to only save the image path in database, your image is in your project only.. like, if your images in MyImages folder of asp.net application and having name "test.jpg" then save the path like "~/MyImages/test.jgp" when you bind that path dynamically to your image control it will pick the image from given path and display it.. so there is no need to store image is database..
Rate this:
Please Sign up or sign in to vote.

Solution 3

Will do in 2 steps
1)You need to save image url in database and same image you need to save in your project folder using property
FileUpload1.SaveAs(strSavePath)

where fileUpload1 is the fileupload control and strSavePath is the variable where you assigned the path where you want to save the image.

2)Now following snippet is the part of grid view control ,that is template field by using template field you add asp:image cotrol and give the column name as value to the property imageUrl of asp.net image control as
ImageUrl ="'<%# Eval("Url") %>'"


<asp:TemplateField>

    <HeaderTemplate>
        <asp:Label ID="lblimg" runat="server">Image</asp:Label>
    </HeaderTemplate>
    <ItemTemplate>
    <asp:Image ImageUrl ="'<%# Eval("Url") %>'" runat="server"  ID="imgCar" />
    &lt;/ItemTemplate&gt;
    &lt;ItemStyle HorizontalAlign=&quot;Center&quot; /&gt;
&lt;/asp:TemplateField&gt;</pre>


now just bind the datatable to gridview ,your work is done.

Quote:
After looking the comment for JsonMacD. i can say that you need to play at database level also with this above coding as following way.


create user defined function like this
create function fnreturn(@RoleId int) returns  varchar(50)
as
Begin
Declare @Result varchar(50)
if((select count(*) from DashBoardItems  where roleId=@RoleId)>2)
Begin
set @Result= '~/Image/upArrow.png'
End
Else
Begin
set @Result= '~/Image/DownArrow.png'
END
return @Result
ENd

which will return based on condition
and then use this function in your select query like this
select *,dbo.fnreturn(8) as URl from DashBoardItems  

then now just you need to bind the result table to gridview.

Hope This will help-Happy coding
   
v2
Comments
Am Gayathri 13-Mar-13 3:07am
   
I cant store the image in Database need to do in other ways
kishore sharma 13-Mar-13 3:22am
   
its not about storing image in database,here you need to store just image path(just the path of the folder where you are storing the image in project folder)ex.if folder name is Image and your image name is carImg.gif then you need to store "~Image/carimg.gif" something like this in database column.
Rate this:
Please Sign up or sign in to vote.

Solution 6

just create a Image type cell with in the grid and then provide image source to that cell when ever you want to show image of up arrow. I think in that way you can achieve to show image but not storing them in DB even if you binding gridview from dataset table.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100