Hi there
I have a gridview which I binded with an access database and within in this gridview I have and ImageButtonField and a regular button as well. The image button field displays and image and the url of this image is retrieved from the database.
When I click on the regular button then I am directed to a different page where I can few detail of the row entry of the gridview.
I want to achieve the same thing with the image button but I am really struggling with this.
Each of the imgages of each concecutive image button is of course different and the data in each row is of cource unique .
Any advice as to how to add functionality the imagebuttonField so as to be redirected from the gridview page(without errors) and display the row information on a new page?.
I have done it relatively easily with the regualar button field and here is the code for the button field.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "addToSession")
{
int index = Convert.ToInt32(e.CommandArgument);
//get the gridview row where the command is raised
GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];
//values stored in the text property of the cells
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");
}
}
}
here is the html for the image button.
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl='<%#Eval("pictureUrl") %>'
CommandName="ratedBooks" />
</ItemTemplate>
</asp:TemplateField>
Thanks and kind regards
Arian