2014-04-11 21 views
0

的兩個事件是轉發器itemboungf重複超過要求?

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次,單個圖像

回答

0

repimages_ItemDataBound是當項目在被調用你的中繼器綁定在你的數據源上。如何通過點擊按鈕來調用它?

+0

其實按鈕單擊事件我是一個文件夾中存儲多個圖像和我他們想顯示給用戶點擊那個按鈕,這就是爲什麼我正在考慮這種替代方法是有任何其他方法來做到這一點。這個中繼器可以綁定該文件夾 – VJain

+0

你必須再次綁定中繼器以反映數據更新。 repimages_ItemDataBound處理程序與它沒有任何關係,我想。 – Nanosoft

+0

做了我想做的事情,謝謝你的幫助 – VJain

0

你必須綁定按鈕點擊repImages這將在內部調用repImages_ItemDataBound在你的aspx只要你有這個OnItemDataBound =「repImages_ItemDataBound」

+0

是的,無論我現在做了什麼,但現在中繼器重複50次可以請你chec我張貼我的代碼 – VJain

+0

你想做什麼?你的數據綁定是for循環,所以它會綁定50次,最後一個會覆蓋previos .. –