I want to display values from db to grid view with image file. While using given below code it shows an error. Help me to find a proper solution.
Code:
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" />
You need to change function prototype like below:
protected void Button1_Click(object sender, EventArgs e1)
{
}