Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Events on Gridview click depending on which colum is clicked.

Status
Not open for further replies.

gtjr92

Programmer
May 26, 2004
96
For asp.net 2.0
I have a gridview with two hyperlink fields. I want to execute different events depending on which of the hyperlink columns is clicked. The only event I can get for this is gridview selected index changed. I want to call an event depending on which hyperlink column is clicked not on selected index changed. I know I may have to use template fields to call the event.
Any ideas?
Thanks
 
they are hyperlink fields of the gridview like this
Code:
 <asp:TemplateField HeaderText="Edit">
                <ItemStyle Font-Underline="True" />
                <ItemTemplate>
                    <asp:HyperLink ID="HlinkEdit" runat="server" NavigateUrl='<%# Eval("ClassID", "~/Teachers/TeClasslist.aspx?clid={0}") %>'
                        Text='<%# Eval("ClassName",  "<Strong>Edit</Strong> Assignments for" + " "+  Eval("ClassName")) %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
 
I belive you are going to have to use a template column(s). Then you can grab the hyperlinks on the RowDataBound event and assign an event handler.
 
Ive found ive used this method quite alot within datalists and other custom clicks i need in a datagrid, or repeaters.
Code:
<asp:LinkButton ID="HlinkEdit" runat="server" Text='<%# Eval("ClassName",  "<Strong>Edit</Strong> Assignments for" + " "+  Eval("ClassName")) %>'
[b]
CommandName=actOnThis CommandArgument='<%# Eval("id")%>' OnCommand="viewStuff"
[/b]
></asp:LinkButton >

Sub viewStuff(sender As Object, e As [b]CommandEventArgs[/b])
     If e.CommandArgument < 5 Then
         gotoThisPage(e.CommandArgument)
     Else
         gotoThatPage(e.CommandArgument)
     End If
End Sub
 
That does not solve my problem.
I use the hyperlink/link button field to pass a query string, and also on the click it changes my details view to insertmode. When clicking on this The query string is not passed to the url.

Code:
<asp:TemplateField HeaderText="Add New">
                <ItemStyle Font-Underline="True" />
                <ItemTemplate>
                  <asp:LinkButton ID="HlinkNewAssign" runat="server" Text='<%# Eval("ClassName",  "<Strong>Edit</Strong> Assignments for" + " "+  Eval("ClassName")) %>'
                commandName="LnkClick" CommandArgument='<%# Eval("Classid")%>' OnCommand="NewAssign"></asp:LinkButton>
                </ItemTemplate>
Code:
                <%--<ItemTemplate>
                    <asp:LinkButton ID="HlinkNewAssign"   runat="server" NavigateUrl='<%# Eval("ClassID", "~/Teachers/TeClasslist.aspx?clid={0}") %>'
                        Text='<%# Eval("ClassName",  "Add <strong>New</strong> Assignments to" + " " +  Eval("ClassName")) %>'></asp:LinkButton>
                </ItemTemplate>--%>
            </asp:TemplateField>

Code:
Protected Sub NewAssign(ByVal Sender As Object, ByVal E As CommandEventArgs)
        
        dvAssignEdit.ChangeMode(DetailsViewMode.Insert)
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top