开发者

how to bind imageurl of datalist to the image control which is out side of datalist on insert command

I have a image coltrol out side of datalist, I want to assign the image url to 开发者_Go百科this image control on insert command.

Data List:

<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>

image control out side the datalist:

<div id="loadarea" class="imageViewArea">
        <asp:Image ID="imgthumb" runat="server" />
    </div>

insert command:

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; 

Or I've missed something in your question?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜