Adding functionality to an imageButton in a gridview
<p>I have an ImageButton control as part of a GridView control that is displayed as an ItemTemplate and in the same GridView. I have a regular Button control to which I added some code like this</p>

<pre><code>if (e.CommandName == "addToSession")
{
    int index = Convert.ToInt32(e.CommandArgument);

    GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];

    string ISBN = selectedRow.Cells[0].Text;
    string bookTitle = selectedRow.Cells[1].Text;
    string image = selectedRow.Cells[2].Text;

    //storing title, author, pictureUrl into session variables to 'carry them over' to RateBook.aspx
    Service s = new Service();
    Session["ISBN"] = ISBN;
    Session["bookTitle"] = bookTitle;
    Session["ImageUrl"] = s.returnImageUrl(bookTitle);

    if (Session["userName"] == null)
    {
        Response.Redirect("registerPage.aspx");
    }
    else
    {
        Response.Redirect("RateBook.aspx");
    }
}
else if (e.CommandName == "ratedBooks")
{
    int index = Convert.ToInt32(e.CommandArgument);

    GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];

    string bookTitle = selectedRow.Cells[1].Text;

    Service s = new Service();

    Session["ImageUrl"] = s.returnImageUrl(bookTitle);

    Response.Redirect("BookRated.aspx");
}
</code></pre>

<p>when I run this code I get a format exception and again I am not sure why. I have altered the image button a bit and nested the image in a link button which seems to be more correct.</p>

<pre><code>&lt;asp:TemplateField&gt;
    &lt;ItemTemplate&gt;
        &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="ratedBooks"&gt;
            &lt;asp:Image ID="ImageButton1" ImageUrl='&lt;%#Eval("pictureUrl") %&gt;' runat="server" /&gt;   

        &lt;/asp:LinkButton&gt;    
    &lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
</code></pre>

<p>Please advise.</p>

<p>Regards,</p>

<p>Arian</p>
