ASP 2.0 GridView using Hyperlink problem

Discussion in 'ASP .Net' started by Ralf, Jul 25, 2007.

  1. Ralf

    Ralf Guest

    I need to use a gridview that has a hyperlink as one of the fields.
    The fields need to be databound. When the user presses the hyperlink,
    I do not want to navigate to another page. I want to store the ID of
    the row. The user will then use buttons on the page that represents
    what they want to do to that row. Delete, update, etc. Here is the
    code for the gridview.
    NOTE: Removed some parts of this, like datasourceID and things.
    Didn't format well on the post


    <cc1:GridViewSD ID="gvwORLList" runat="server" AllowPaging="True"
    AllowSorting="True"
    ArrowDownUrl="~/images/sortdescending.gif" rowUpUrl="~/images/
    sortascending.gif"
    AutoGenerateColumns="False" CellPadding="4"
    HorizontalAlign="Left" />
    <Columns>
    <asp:BoundField DataField="template_name"
    HeaderText="Record Title" SortExpression="template_name" />
    <asp:BoundField DataField="CALENDAR_year"
    HeaderText="Year" SortExpression="CALENDAR_year" />
    <asp:BoundField DataField="Column1" HeaderText="Status"
    ReadOnly="True" SortExpression="Column1" />

    </Columns>
    </cc1:GridViewSD>
    Ralf, Jul 25, 2007
    #1
    1. Advertising

  2. Ralf

    lee whitbeck Guest

    On Jul 25, 11:06 am, Ralf <> wrote:
    > I need to use a gridview that has a hyperlink as one of the fields.
    > The fields need to be databound. When the user presses the hyperlink,
    > I do not want to navigate to another page. I want to store the ID of
    > the row. The user will then use buttons on the page that represents
    > what they want to do to that row. Delete, update, etc. Here is the
    > code for the gridview.
    > NOTE: Removed some parts of this, like datasourceID and things.
    > Didn't format well on the post
    >
    > <cc1:GridViewSD ID="gvwORLList" runat="server" AllowPaging="True"
    > AllowSorting="True"
    > ArrowDownUrl="~/images/sortdescending.gif" rowUpUrl="~/images/
    > sortascending.gif"
    > AutoGenerateColumns="False" CellPadding="4"
    > HorizontalAlign="Left" />
    > <Columns>
    > <asp:BoundField DataField="template_name"
    > HeaderText="Record Title" SortExpression="template_name" />
    > <asp:BoundField DataField="CALENDAR_year"
    > HeaderText="Year" SortExpression="CALENDAR_year" />
    > <asp:BoundField DataField="Column1" HeaderText="Status"
    > ReadOnly="True" SortExpression="Column1" />
    >
    > </Columns>
    > </cc1:GridViewSD>


    Rather than doing it that way, have you considered enabling the
    AutoGenerateEdit or Select buttons on the GridView? It will allow you
    to edit/update/delete the items of that row when selected?

    Alternatively, you could create an ItemTemplate, and then simply embed
    whatever server side control you want. When the user presses your
    link, you could then enable/disable the controls that you have for
    that ItemTemplate on the server side. Here is an example using an
    Image Button, which you can change to a hyperlink for your case.

    <ItemTemplate>
    <ul>
    <li>
    <asp:ImageButton ID="ImageButton1"
    runat="server" OnClick="FormatImageNavigation" ImageUrl='<%#
    (string) FormatImageUrl( (int) Eval("ID"),(int) Eval("TYPE_ID"),
    (string) Eval("NAME"),(string) Eval("PATH") ) %>' Width="200"
    Height="250"/>
    </li>
    </ul>
    </ItemTemplate>
    </ItemTemplate>
    lee whitbeck, Jul 25, 2007
    #2
    1. Advertising

  3. Ralf

    Ralf Guest

    Thx for the response. The commands the user can do are actually
    update, rename, view, and submit. I don't want the grid to have 4
    different buttons beside each row. I want to store the ID of the row
    when the user selects the row. Are you telling me I can setup the
    hyperlink as an itemtemplate and just set the onclick event to call
    the function to store the ID for future use of pressing the buttons?
    Ralf, Jul 25, 2007
    #3
  4. Ralf

    David Wier Guest

    Sure - use the OnSelectedIndexChanged event - assign the row:
    Dim row As GridViewRow = MyGridView.SelectedRow
    Dim intRow as Integer=Row.RowIndex
    (or something close to this)


    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://iWritePro.com



    "Ralf" <> wrote in message
    news:...
    > Thx for the response. The commands the user can do are actually
    > update, rename, view, and submit. I don't want the grid to have 4
    > different buttons beside each row. I want to store the ID of the row
    > when the user selects the row. Are you telling me I can setup the
    > hyperlink as an itemtemplate and just set the onclick event to call
    > the function to store the ID for future use of pressing the buttons?
    >
    David Wier, Jul 25, 2007
    #4
  5. Ralf

    lee whitbeck Guest

    On Jul 25, 12:22 pm, "David Wier" <>
    wrote:
    > Sure - use the OnSelectedIndexChanged event - assign the row:
    > Dim row As GridViewRow = MyGridView.SelectedRow
    > Dim intRow as Integer=Row.RowIndex
    > (or something close to this)
    >
    > --
    > David Wier
    > MVP/ASPInsiderhttp://aspnet101.comhttp://iWritePro.com
    >
    > "Ralf" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Thx for the response. The commands the user can do are actually
    > > update, rename, view, and submit. I don't want the grid to have 4
    > > different buttons beside each row. I want to store the ID of the row
    > > when the user selects the row. Are you telling me I can setup the
    > > hyperlink as an itemtemplate and just set the onclick event to call
    > > the function to store the ID for future use of pressing the buttons?- Hide quoted text -

    >
    > - Show quoted text -


    Yes.. That is one way of doing it.
    lee whitbeck, Jul 25, 2007
    #5
  6. Ralf

    Ralf Guest

    I get errors b/c it seems to be expecting a URL to be assigned.
    Ralf, Jul 26, 2007
    #6
    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. davetichenor
    Replies:
    1
    Views:
    803
    Eliyahu Goldin
    Oct 30, 2006
  2. Valli
    Replies:
    3
    Views:
    2,897
    =?Utf-8?B?QW5kcmV3IEhheWVz?=
    Sep 28, 2007
  3. Keith G Hicks
    Replies:
    3
    Views:
    746
    Keith G Hicks
    Feb 18, 2008
  4. Ken
    Replies:
    1
    Views:
    360
    Alvin Bruney
    Aug 16, 2003
  5. Dave
    Replies:
    0
    Views:
    922
Loading...

Share This Page