2011-07-22 112 views
0

我有在一個LinkBut​​ton的點擊需要一個單獨的頁面一個獨立的頁面

aspx page 
    detail view: 
    <asp:TemplateField HeaderText="Evidence (if any)"> 
        <ItemTemplate> 
        <asp:LinkButton ID="lbEvidence" runat="server" 
        Text='<%# DataBinder.Eval(Container.DataItem, "Evidence").ToString() == String.Empty ? "None" : DataBinder.Eval(Container.DataItem, "Evidence")%>' 
          CommandName="Select" CommandArgument = '<%# DataBinder.Eval(Container.DataItem, "Complaint_Id") %>'> </asp:LinkButton> 
         </ItemTemplate> 
        </asp:TemplateField> 

ImageHandler.ashx

<%@ WebHandler Language="C#" Class="FMMadminModule.imageHandler" %> 

using System; 
using System.Web; 
using System.Data; 
using System.Web.SessionState; 

    namespace FMMadminModule 
    { 
    public class imageHandler : IHttpHandler, IReadOnlySessionState 
    { 
    DataTable dt; 
    int key; 
    byte[] imageOut; 
    public void ProcessRequest(HttpContext context) 
    {    
     HttpResponse response = context.Response; 
     HttpRequest request = context.Request; 
     context.Response.ContentType = "image/jpeg"; 
     response.BufferOutput = false; 
     // get the key, the index into the DataTable 
     key = Convert.ToInt32(request.QueryString["Complaint_ID"]);   
     // Prepare the datatable to hold the SNo key and the jpeg image, which will be written out 
     dt = new DataTable(); 
     dt = (DataTable)context.Session["dt"]; 
     if (!dt.Rows[key]["Evidence"].Equals(null)) 
     { 
      imageOut = (byte[])dt.Rows[key]["Evidence"]; 
      response.OutputStream.Write(imageOut, 0, imageOut.Length); 
     } 
    } 

    public bool IsReusable 
    { 
     get 
     { 
      return false; 
     } 
    } 
} 
} 

我將如何顯示上顯示一個圖像數據類型上顯示圖像圖像在一個單獨的頁面上? 這是aspx.cs的樣子

protected void dvResolveComplaint_ItemCommand(object sender, DetailsViewCommandEventArgs e) 
    { 
     if (e.CommandName == "Select") 
     { 
      DetailsViewRow row = dvResolveComplaint.Rows[5]; 
      //String RowId = (e.NewSelectedIndex).ToString(); 
      Type csType = this.GetType(); 
      String strScript = "<script> "; 
      strScript += @"var newWindow = window.open('imageHandler.ashx?Complaint_ID=" + e.CommandArgument + @"', 'Evidence', ' height=450, center:yes, width=600, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=no, status=no')"; 
      strScript += "</script>"; 
      ClientScript.RegisterClientScriptBlock(csType, "ViewEvidence", strScript); 
      dvResolveComplaint.Attributes.Add("OnClick", strScript); 
     } 
    } 

回答

1

這是後過於複雜。您根本不需要鏈接按鈕,只需在項目模板中編寫一個錨定包裝的圖像並將其稱爲一天,例如:

<a href='url_to_your_handler' target="_blank"><img src='url_to_your_handler' alt='complaint image' /></a>