如何在数据表中的行中添加图像? [英] How can i add image inside a row in a Data Table?

查看:96
本文介绍了如何在数据表中的行中添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?





这里检查一些值,例如任何单元格中的值如果大于50,它应该在该单元格内显示一个向上箭头。从DB.In .net侧检查值是否过滤像

if(value> 50)

{

dt.rows [] =这里我要展示一个向上的箭头

}

那我怎么能这样做?不需要将值存储在DB中吗?



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?

推荐答案

这应该逐步解答您的问题:



http://www.dotnetfunda.com/articles/article1084-saving-images-into-the-database-in-aspnet-and-displaying-to-the-gridview-.aspx [ ^ ]
This should answer your question, in a step-by-step fashion:

http://www.dotnetfunda.com/articles/article1084-saving-images-into-the-database-in-aspnet-and-displaying-to-the-gridview-.aspx[^]


将图像路径存储在数据库中...并在网格视图中进行图像控制,当您绑定gridview时绑定图像图像控件的ImageUrl属性的路径,它将在gridview中显示图像。
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.


将分2步完成

1)您需要在数据库中保存图像URL以及需要在项目中保存的相同图像lder使用属性
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)



其中fileUpload1是fileupload控件,strSavePath是你为其指定路径的变量想要保存图像。



2)现在,以下片段是网格视图控件的一部分,即模板字段,使用模板字段添加asp:image cotrol和将列名作为值提供给asp.net图像控件的属性imageUrl为


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>





现在只需将数据表绑定到gridview,您的工作就完成了。





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

Quote:

查看JsonMacD的评论后。我可以说你需要在数据库级别玩这个以上编码,如下所示。

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


这篇关于如何在数据表中的行中添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆