Repeater itemboungf重复超过要求?

时间:2014-04-11 08:56:53

标签: asp.net c#-4.0 event-handling

这两个事件是

 protected void btnuplaod_Click(object sender, EventArgs e)
{

    string filepath = Server.MapPath(@"~/Admin/temp/");
    Session["Image"] = Request.Files;
    HttpFileCollection uploadedFiles = (HttpFileCollection)Session["Image"];
    lblerror.Text = string.Empty;

    for (int i = 0; i < uploadedFiles.Count; i++)
    {
        HttpPostedFile userPostedFile = uploadedFiles[i];

        try
        {
            if (userPostedFile.ContentLength > 0)
            {
                lblerror.Text += "<u>File #" + (i + 1) + "</u><br>";
                lblerror.Text += "File Content Type: " + userPostedFile.ContentType + "<br>";
                lblerror.Text += "File Size: " + userPostedFile.ContentLength + "kb<br>";
                lblerror.Text += "File Name: " + userPostedFile.FileName + "<br>";
                userPostedFile.SaveAs(filepath + Path.GetFileName(userPostedFile.FileName));
                lblerror.Text += "Location where saved: " + filepath + "\\" + Path.GetFileName(userPostedFile.FileName) + "<p>";

            }
            repimages.DataSource = filepath;
            Session["repimage"] = userPostedFile.FileName;
            repimages.DataBind();
        }
        catch (Exception Ex)
        {
            lblerror.Text += "Error: <br>" + Ex.Message;
        }
    }
}

 protected void repimages_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string filepath = Server.MapPath(@"~/Admin/temp/");
        lblerror.Text = string.Empty;
            Image img = e.Item.FindControl("postedimage") as Image;
            img.ImageUrl = filepath + Session["repimage"];
    }

repimages_ItemDataBound(对象发送者,RepeaterItemEventArgs e)事件为单个图像重复48次

2 个答案:

答案 0 :(得分:0)

当您的转发器中的项目与数据源绑定时,将调用

repimages_ItemDataBound 。如何通过单击按钮来调用它?

答案 1 :(得分:0)

你必须在点击按钮时绑定repImages,这将在内部调用你的aspx中提供的repImages_ItemDataBound你有这个OnItemDataBound =“repImages_ItemDataBound”