2014-10-16 46 views
0

對於數據訪問層:如何使用3層體系結構在gridview中顯示圖像?

來源:

public string insert_details(bisuness_object user_details) 
{ 

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 
    con.Open(); 
    SqlCommand cmd = new SqlCommand("insert into tbl_rgsthome values(@firstname,@lastname,@emailid,@password,@address,@upload)", con); 
    try 
    { 
     cmd.Parameters.AddWithValue("@firstname", user_details.firstname_value); 
     cmd.Parameters.AddWithValue("@lastname", user_details.lastname_value); 
     cmd.Parameters.AddWithValue("@emailid", user_details.emailid_value); 
     cmd.Parameters.AddWithValue("@password", user_details.pass_value); 
     cmd.Parameters.AddWithValue("@address", user_details.addr_value); 
     cmd.Parameters.AddWithValue("@upload", user_details.fileupl_value); 
     //cmd.Parameters.AddWithValue("@imagepath", user_details.imgpth_value); 
     return cmd.ExecuteNonQuery().ToString(); 
    } 
    catch (Exception show_error) 
    { 
     throw show_error; 
    } 
    finally 
    { 
     cmd.Dispose(); 
     con.Close(); 
     con.Dispose(); 
    } 

} 

home.aspx:

public string getimage(object ob) 
{ 
    string img = @"/image/" + ob.ToString(); 
    return img; 
} 

protected void Button1_Click(object sender, EventArgs e) 
{ 
    if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") 
    { 

     byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength]; 
     HttpPostedFile Image = FileUpload1.PostedFile; 
     Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength); 
     bisuness_object bo = new bisuness_object(); 
     // cmd.Parameters.AddWithValue("@imagepath", ("@uploadimage") + filename); 
     bo.firstname_value = TextBox1.Text; 
     bo.lastname_value = TextBox2.Text; 
     bo.emailid_value = TextBox3.Text; 
     bo.pass_value = TextBox4.Text; 
     bo.addr_value = TextBox6.Text; 
     bo.fileupl_value = FileUpload1.FileName.ToString(); 
     bisuness_layer bl = new bisuness_layer(); 
     bind(); 

     try 
     { 
      string result = bl.record_insert(bo); 
     } 
     catch (Exception info) 
     { 
      throw info; 
     } 
     finally 
     { 
      bo = null; 
      bl = null; 
      bind(); 
     } 
     TextBox1.Text = ""; 
     TextBox2.Text = ""; 
     TextBox3.Text = ""; 
     TextBox4.Text = ""; 
     TextBox5.Text = ""; 
     TextBox6.Text = ""; 
    } 
} 

如何解決這個問題.....請幫我 我想gridview中的圖像

+1

在哪裏你gridview? – Reniuz 2014-10-16 13:10:59

回答

1

綁定gridview裏面的圖片標籤dy通過爲路徑動態

<asp:Image ID="image" Style="width:100px; height:100px;" runat="server" ImageUrl='<%# "~/folder/subfolder/" + Eval("id") +"."+ Eval("imagetype") %>' /> 

和綁定gridview的

protected void GetDayoffer() 
{ 

    gridview1.DataSource = bl.method(); 
    gridview1.DataBind(); 
} 

希望這會幫助你,或再次人們重新字節爲圖像,並將其綁定到gridview的方法namically