The error is pretty much self-explanatory. This means that you cannot cast the SelectedValue to a DataRow because the SelectedValue will return an integer. Also If you want to get the SelectedRow, you might want to handle it at SelectedIndexChanged event.
But keep in mind that in order to fire the SelectedIndexChanged event, you need to setup the ShowSelectButton CommandField or set the AutoGenerateSelectButton to true in your GridView. For example:
<asp:gridview id="GridView1" runat="server"
AutoGenerateColumns="False"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<columns>
<asp:commandfield showselectbutton="True" />
<asp:boundfield />
<asp:boundfield />
</columns>
</asp:gridview>
Then you can reference the Image control like this:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Image img = (Image)GridView1.SelectedRow.FindControl("TheImageID");
if(img != null){
}
}
But since you want to save the image as blob, then I don't think your existing code will work. You would need to upload the image first and then stream the uploaded image to get the byte array. There are tons of examples that demonstrate about that, you just need to find them at google.
This one is one of them:
Save and Retrieve BLOB Images from MySql Database in ASP.Net, C# and VB.Net[
^]