ASP.Net在GridView中显示图像跨越列和行?使用C# [英] ASP.Net Display Images in a GridView span across columns and rows? Using C#

查看:108
本文介绍了ASP.Net在GridView中显示图像跨越列和行?使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Gridview中显示一些缩略图。我不熟悉所提供的所有定制。基本上我想将图像存储在一个GridView中,也许跨越5列宽...然后无论多少行都需要完成剩下的工作。我不想要任何列或行标题,并且真的不想看到实际网格的证据。我也想让图像可点击。

我将从Asp.net中的Sql数据库中提取图像。我不想将网格绑定到sqldatasource,而是将图像粘贴到网格中,并在页面后面的代码中使用某种循环。这是让我感到困惑的地方。我知道你可以创建一个数据表并添加列和行。但是,似乎行/列不能跨越。你将如何存储图像,使其像网格一样工作。我在下面提供了一些(非常)的sudo代码,让你知道我在做什么。

sudo代码:

  colcount = 0; 
rowcount = 0;
imagecount = 0;
while(images.length> imagecount){
if(colcount< 5){
grid [rowcount] [colcount] = images [imagecount];
colcount ++;
imagecount ++;
}
else {
rowcount ++;
colcount = 0;
}
}


解决方案

你需要特定的HTML,那么你最终会在整个时间内与GridView交战。改为使用ListView或Repeater。

 < asp:ListView runat =server> 
< LayoutTemplate>
< table>
< asp:PlaceHolder id =itemPlaceHolderrunat =server/>
< / table>
< / LayoutTemplate>
< ItemTemplate>
< tr>
< td colspan =5>< asp:Image runat =serversrc ='<%#Eval(ImageUrl)'%>< / td>
< td><%#Eval(Column1)%>< / td>
< / tr>
< / ItemTemplate>
< / asp:ListView>




我知道你可以创建一个数据表并添加行和列。然而,它似乎像行/列不跨越。

这听起来像你正在创建一个 System.Data.DataTable - 这是一个数据结构 - 不是布局控件。如果您想以编程方式创建< table> ,您可以使用 System.Web.UI.WebControls.Table a System.Web.UI.HtmlControls。 HTMLTABLE 。您可以在相关的TableRow或HtmlTableRow上设置colspan和rowspan。


I have some thumbnails I want to display in a Gridview. I am not familiar with all the customization that is offered. Basically I want to store the images in a Gridview, maybe spanning 5 columns wide...and then however many rows it takes to complete the rest. I don't want any column or row titles, and really don't want to see evidence of the actual grid. I also want to make the images clickable.

I will be pulling the images from an Sql database in Asp.net. I do not want to bind the grid to an sqldatasource, but rather stick the images in the grid with some sort of loop in the code behind the page. This is where it gets confusing to me. I know you can create a datatable and add columns and rows. However, it seems like the rows/columns do not span. How would you store the images so that it worked like a grid. I provided some (very)sudo code below to give you an idea of what I am trying to do.

sudo code:

colcount = 0;  
rowcount = 0;  
imagecount = 0;  
while(images.length > imagecount){  
    if(colcount < 5){  
        grid[rowcount][colcount] = images[imagecount];  
        colcount++;  
        imagecount++;  
    }  
    else{  
        rowcount++;
        colcount = 0; 
    }
}  

解决方案

If you want specific HTML, then you'll end up fighting the GridView in the entire time. Use a ListView or Repeater instead.

<asp:ListView runat="server">
   <LayoutTemplate>
      <table>
         <asp:PlaceHolder id="itemPlaceHolder" runat="server" />
       </table>
   </LayoutTemplate>
   <ItemTemplate>
          <tr>
             <td colspan="5"><asp:Image runat="server" src='<%# Eval("ImageUrl")' %></td>
             <td><%# Eval("Column1") %></td>
          </tr>
   </ItemTemplate>
 </asp:ListView>

I know you can create a datatable and add columns and rows. However, it seems like the rows/columns do not span.

It sounds like you're creating a System.Data.DataTable - which is a data structure - not a layout control. If you wanted to create the <table> programatically, you could use either System.Web.UI.WebControls.Table a System.Web.UI.HtmlControls.HtmlTable. You can set colspan and rowspan on the associated TableRow or HtmlTableRow on those.

这篇关于ASP.Net在GridView中显示图像跨越列和行?使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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