ASP 2.0 GridView using Hyperlink problem

R

Ralf

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>
 
L

lee whitbeck

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>
 
R

Ralf

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?
 
D

David Wier

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)
 
L

lee whitbeck

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






- Show quoted text -

Yes.. That is one way of doing it.
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top