我希望使用图像文件显示从db到网格视图的值。使用下面给出的代码时,它显示错误。帮我找一个合适的解决方案。
代码:
protected void Button1_Click(object sender, GridViewRowEventArgs e1)
{
ShadingAnalysisDataSetTableAdapters.tbl_SiteLayOutUploadTableAdapter sl;
sl = new ShadingAnalysisDataSetTableAdapters.tbl_SiteLayOutUploadTableAdapter();
DataTable dt = new DataTable();
dt = sl.GetGridData(ddlSit.SelectedValue, int.Parse(ddlVersion.SelectedValue));
try
{
if (e1.Row.RowType == DataControlRowType.DataRow && gvEdit.EditIndex == e1.Row.RowIndex)
{
Image Image1 = (Image)e1.Row.FindControl("Image1");
foreach (DataRow row in dt.Rows)
{
byte[] img1 = (byte[])row["ImgData"];
string base1 = Convert.ToBase64String(img1);
Image1.ImageUrl = "data:image/jpg;base64," + base1;
}
}
gvEdit.DataSource = dt;
gvEdit.DataBind();
}
catch (NullReferenceException ex)
{
}
}
ASPX:
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
答案 0 :(得分:2)
您需要更改功能原型,如下所示:
protected void Button1_Click(object sender, EventArgs e1)
{
}
答案 1 :(得分:1)
Button1_Click
的参数错误。它应该如下所示。
protected void Button1_Click(object sender, EventArgs e)
{
}