如何在insert命令中将数据列表的imageurl绑定到数据列表外侧的图像控件
本文关键字:数据 列表 绑定 控件 图像 imageurl 命令 insert | 更新日期: 2023-09-27 18:05:44
我在数据列表的外侧有一个图像控件,我想在insert命令中将图像url分配给这个图像控件。
数据列表:
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Vertical" onitemcommand="DataList1_ItemCommand" onitemdatabound="DataList1_ItemDataBound" CaptionAlign="Right" CellSpacing="6">
<ItemTemplate>
<asp:ImageButton ID="Image" runat="server" ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
OnCommand="Insert_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("FilePath")%>' />
<asp:Label ID="lblimagenumber" runat ="server" Text='<%# DataBinder.Eval(Container.DataItem, "FileName") %>' ></asp:Label>
</ItemTemplate>
</asp:DataList>
数据列表外的图像控制:
<div id="loadarea" class="imageViewArea">
<asp:Image ID="imgthumb" runat="server" />
</div>
插入命令:
protected void Insert_Command(object sender, CommandEventArgs e)
{
string[] str = e.CommandArgument.ToString().Split(';');
hImgInsId.Value = str[0];
ImgName = str[1];
//Image imgThumb = (Image)this.FindControl("imgthumb");
//imgThumb.ImageUrl=
//how to assign datalist image url to image contol here...?
// this is datalist imagebtn imageurl ImageUrl='<%#"~/Controls/ShowImage.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>'
}
public void BindImages()
{
List<int> ImgIds = new List<int>();
List<string> imgFileName = new List<string>();
txbCaption.Text = "";
if (ImgUpLoad.ImgFleIds != null)
ImgIds = ImgUpLoad.ImgFleIds;
if (ViewState["imgIds"] != null)
{
List<int> oldids = (List<int>)ViewState["imgIds"];
ImgIds.AddRange(oldids);
ImgIds.Sort();
}
path = objGetBaseCase.GetImages(ImgIds);
for (int i = 0; i < path.Count; i++)
{
ArrayList alst = path[i];
if (i == 0)
hImgInsId.Value = alst[0].ToString();
tb.Rows.Add(Convert.ToInt32(alst[0]), "Figure " + (i + 1).ToString(), alst[2].ToString());
imgIds.Add(Convert.ToInt32(alst[0]));
imgFileName.Add(alst[2].ToString());
}
ViewState["imgIds"] = imgIds;
ViewState["imgFileName"] = imgFileName;
DataList1.DataSource = tb;
DataBind();
ImgIds.Clear();
if (DataList1.Items.Count == 1)
{
Label lblimgname = (Label)DataList1.Items[0].FindControl("lblimagenumber");
lblimgname.Style.Add(HtmlTextWriterStyle.Color, "Red");
lblimgname.Font.Bold = true;
if (imgIdCapHtbl != null && imgIdCapHtbl.ContainsKey(imgIds[0]))
txbCaption.Text = imgIdCapHtbl[imgIds[0]].ToString();
}
}
imgThumb.ImageUrl="~/Controls/ShowImage.ashx?FileName=" +ImgName;
或者我在你的问题中遗漏了什么?