【发布时间】:2011-09-22 10:52:38
【问题描述】:
使用 GridView1.DataBind(); 和 AutoGenerateColumns="true" 如何找到特定列而不是 URL 显示来自该 URL 的图像缩略图?
GridView 是作为 SQL 查询的结果生成的,它可能返回 2 到 10 列(其中之一可能是图像 URL。)。
对于缩略图,我相信可以使用image.GetThumbnailImage(),但是在这种情况下应该在哪里使用呢?
生成 SQL 查询:
if (CheckBoxUser.Checked) search_fields += "UserName";
if (CheckBoxDate.Checked) search_fields += ",EventDate";
...
if (CheckBoxImageUrl.Checked) search_fields += ",ImageUrl";
SqlConnection conn = new SqlConnection(connectionString);
string select = "SELECT " + search_fields + " FROM TableName";
SqlDataAdapter DataCommand = new SqlDataAdapter(select, conn);
DataCommand.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
GridView1 很简单:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True">
<HeaderStyle CssClass="header_grid" />
</asp:GridView>
没有手动声明列,因为我们不知道用户想要浏览多少列。但如果他标记“ImageUrl”列,那么他需要在 GridView 中查看此图像的缩略图,而不是网络文件路径 (\somePc\path\file.jpg)。
【问题讨论】:
-
@just_name 我在示例中解释了更多..
标签: c# asp.net gridview sql-server-express