ASP .NET 2.0 GridView Question

G

Guest

Hi,

So I am trying to have a <asp:ButtonField> in the columns part of my
gridview, redirect the user to another page with the index/DataValue of the
Row that they pushed the button in. It would be nice if there was a combined
thing with <asp:ButtonField and <asp:HyperLinkField. Since there is not, how
would I accomplish my objective. By clicking a button with my own specified
image that redirects the user to another page. I tried:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditItem")
{
try
{
int index = Convert.ToInt32(e.CommandArgument);
GridView1.SelectedIndex = index;
int id = Convert.ToInt32(GridView1.SelectedValue);
Response.Redirect(string.Format("EditSku.aspx?id={0}", id));
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}


But the Response.Redirect is throwing an exception.

Thanks,
Matt
 
G

Guest

A couple of Questions down is what I am asking. Have an image in the
gridview, how do I make it take the user to another page when clicked on.
 
G

Guest

There are 2 overloads for the Response.Redirect, use the second:

1) HttpResponse.Redirect (String) Redirects a client to a new URL and
specifies the new URL.

2) HttpResponse.Redirect (String, Boolean) Redirects a client to a new URL.
Specifies the new URL and whether execution of the current page should
terminate.

http://msdn2.microsoft.com/t9dwyts4.aspx
A quote from the above link to explain why:
"Calling Redirect is equivalent to calling Redirect with the second
parameter set to true.
Redirect calls End which raises a ThreadAbortException exception upon
completion."

http://msdn2.microsoft.com/a8wa7sdt(en-US,VS.80).aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top