gpt4 book ai didi

c# - 如何在代码中更改我的 GridView 中的图像 DataImageUrlFormatString 值?

转载 作者:行者123 更新时间:2023-11-30 21:25:13 24 4
gpt4 key购买 nike

我有一个 GridView ,其中一个是图像列。我将如何更改后面代码中的 DataImageUrlFormatString 值?

我试过这样做,但它不起作用......

((ImageField)(GridView2.Rows[0].Cells[0].FindControl("ID"))).DataImageUrlFormatString 

= "~/createthumb.ashx?gu=/pics/gmustang06_2.jpg";

最佳答案

试试这个:

 ((System.Web.UI.WebControls.Image)(GridView2.Rows[0].Cells[0].Controls[0])).ImageUrl = "~/createthumb.ashx?gu=/pics/gmustang06_2.jpg";

编辑:

您可以使用声明性语法将路径的 URL 设置为将在图像控件中显示的图像:

<asp:ImageField DataImageUrlField="id" DataImageUrlFormatString="img{0}.jpg"></asp:ImageField>

或在代码隐藏中通过处理 GridView 控件的 OnRowDataBound 事件:

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = e.Row.Cells[0].Controls[0] as Image;
img.ImageUrl = "img" + DataBinder.Eval(e.Row.DataItem, "id") + ".jpg";
}
}

关于c# - 如何在代码中更改我的 GridView 中的图像 DataImageUrlFormatString 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/785670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com