将动态图像叠加添加到数据绑定 Gridview
我正在尝试在 ASP.Net (C#) 中的数据绑定 gridview 单元格内添加单元格的图像覆盖。该效果被设计为在图像中包含一个字符串,该字符串将位于从服务器拉取的图像之上。
IE:
数据库包含图像路径。数据网格根据相关项目的 ID 提取这些图像。我需要从数据库中提取价格并将其放置到放置在数据绑定图像单元格上的图像上。
SQL语句获取结果。 结果包含项目图像的路径。 商品有时会打折,因此需要特殊的覆盖层。 覆盖将有不同的价格覆盖它。
我试图将其分解为简单的部分。我不确定我是否想得太多,但我找不到可行的方法来做到这一点。由于ASP.Net中的数据网格控件,数据被转换为表格,并且在创建表格后没有任何方法可以确定ID。
如果有人有任何想法,我将不胜感激。
I am trying to add an image overlay of a cell within a data bound gridview cell in ASP.Net (C#). The effect is designed to have a string within the image that is going to sit on top of the image that is pulled from the server.
IE:
Database contains path to images. Data grid is pulling these images in based on the ID of the items in question. I need to pull the price from the database and lay it onto an image that is placed over the data bound image cell.
SQL Statement gets results.
Results contains path to image for items.
Items are sometimes on sale, so a special overlay is needed.
Overlay will have a varying price overlaying it.
I tried to break it down into easy portions. I am not sure if I am over thinking things or not but I can't find a feasible way to do this. The data is converted to a table due to the data grid control in ASP.Net, and there isn't any way to determine the IDs after the table is created.
If anyone has any ideas I would be most appreciative.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用 CSS 将单元格的背景设置为图像,并将价格以纯文本形式写入同一单元格(显示渲染输出):
这种方法的唯一缺点是单元格的大小必须明确调整为与图像相同的尺寸,您可能不知道。
另一种选择是在单元格内使用
元素,并仍然使用
表示纯文本价格(显示渲染输出):
无论哪种方法,您将使用 CSS 来定位单元格中的价格并设置其样式:
一个非常简单的带有模板的 GridView 示例
您需要将 GridView 的
AutoGenerateColumns
属性设置为 false,并自行处理列创建和模板化。One way to do this is to set the cell's background to the image using CSS and write the price as plain text into the same cell (rendered output displayed):
The only downside to this approach is that the cell would have to be explicitly sized to the same dimensions as the image, which you may not know.
Another option is to use an
<img>
element inside the cell and still use a<span>
for the plain text price (rendered output displayed):Regardless of which method, you would use CSS to position and style the price within the cell:
A very simple GridView example with templating
You will need to set the GridView's
AutoGenerateColumns
property to false and handle the column creation and templating yourself.