如何在具有3层架构的gridview中显示图像
本文关键字:gridview 显示 图像 显示图 3层 | 更新日期: 2023-09-27 18:26:49
对于数据访问层:
来源:
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内部的image标记通过动态地给出路径
<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