ASP .NET 2.0 GridView Question

Discussion in 'ASP .Net' started by =?Utf-8?B?SmFmZmE=?=, Jan 20, 2006.

  1. 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
     
    =?Utf-8?B?SmFmZmE=?=, Jan 20, 2006
    #1
    1. Advertising

  2. 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.

    "Jaffa" wrote:

    > 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
     
    =?Utf-8?B?SmFmZmE=?=, Jan 20, 2006
    #2
    1. Advertising

  3. 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
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Jaffa" wrote:

    > 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
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Jan 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Smith jr.

    Data Access with GridView [ASP.Net 2.0] question

    Robert Smith jr., Nov 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,158
    Angelo Cook
    Nov 8, 2005
  2. dm1608

    GridView ASP.NET 2.0 Question

    dm1608, Feb 17, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,419
  3. Bishop

    ASP.NET Dynamic Gridview Question

    Bishop, Mar 23, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    17,279
    Bishop
    Mar 24, 2006
  4. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,044
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  5. Cirene
    Replies:
    1
    Views:
    387
    gnewsgroup
    Nov 4, 2007
Loading...

Share This Page