C# 显示尽可能多的列以适应GridView宽度ASP.NET
我有一个GridView,它由数据库中的图像填充。我当前的GridView如下所示: 但我希望适合我的网格宽度,如下所示: 这是我的代码:C# 显示尽可能多的列以适应GridView宽度ASP.NET,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个GridView,它由数据库中的图像填充。我当前的GridView如下所示: 但我希望适合我的网格宽度,如下所示: 这是我的代码: <asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="100%" GridLines="None"> <Columns> <asp:Ima
<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="100%" GridLines="None">
<Columns>
<asp:ImageField DataImageUrlFormatString="http://myurl/{0}" DataImageUrlField="url" ControlStyle-Height="200px" ControlStyle-Width="200px">
<ControlStyle Height="200px" Width="200px"></ControlStyle>
</asp:ImageField>
</Columns>
</asp:GridView>
请提供任何帮助。在本例中,您可以使用datalist而不是gridview,它有3列 它的工作原理与gridview几乎相同
<asp:DataList ID="dlImages" runat="server" RepeatColumns="4" CellPadding="3" CellSpacing="3"
RepeatDirection="Horizontal">
<ItemTemplate>
<table class="TableBorder">
<tr>
<td class="NormalTextBig" valign="top" align="left">
<%#Container.ItemIndex + 1%>.
</td>
</tr>
<tr>
<td valign="top" align="left">
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="ImageClick" CommandArgument='<%# Eval("PageName") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
我使用此代码的目的与您在我的项目中提到的相同
ItemCommand:
Protected Sub dlImages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlImages.ItemCommand
If e.CommandName = "ImageClick" Then
Session("ImageName") = e.CommandArgument
Response.Redirect("ScreenDetails.aspx")
End If
End Sub
这就是它的样子:
我想你也有类似的事情要做:)
Protected Sub dlImages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlImages.ItemCommand
If e.CommandName = "ImageClick" Then
Session("ImageName") = e.CommandArgument
Response.Redirect("ScreenDetails.aspx")
End If
End Sub