views:

266

answers:

1

Hi All,

I have a linkbutton that is nested in a datagrid that is nested in a datalist (yes, very strange, but unfortunately it's part of the site which I cannot change). Essentially I want the linkbutton to fire an event handler that calls Response.Redirect(e.CommandArgument)). In other words, I already have the URL that I want to redirect to, but I can't figure out how to get the event to trigger when I click on the linkbutton.

I have tried using the linkbutton OnClick events and the ItemCommand events for the datagrid but I dont think I am registering them correctly.

Here is the HTML for the controls.

<asp:DataList ID="dlstC" BorderWidth="0px" BorderStyle="None" CellPadding="2" CellSpacing="0"
runat="server">
<ItemTemplate>
    <table cellpadding="0" cellspacing="0">
        <tr style="padding-bottom: 4px">
            <td style="height: 20px">
                <asp:Label runat="server" ID="lblCertNum" Text='<%# "20" + (CStr(Container.DataItem("QuoteID").ToString) + "-" + CStr(Container.DataItem("QuoteRef").ToString)) %>'
                    Font-Bold="True" Font-Size="8pt"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:DataGrid ID="dgd_Certs" runat="server" ShowHeader="False" AutoGenerateColumns="False"
                    DataSource='<%# GetCert(CInt(Container.DataItem("QuoteRef"))) %>' BorderStyle="None"
                    BorderWidth="0" BorderColor="#ffffff" CellPadding="4" CellSpacing="0" OnItemCommand="DataGrid_EditItem">
                    <Columns>
                        <asp:TemplateColumn>
                            <ItemTemplate>
                                <asp:LinkButton ID="hlnCert" runat="server" Text='<%# Container.DataItem("CertName").ToString  %>' CommandName="RedirectToCert"
                                    CommandArgument='<%# BuildURLToCert(CInt(Container.DataItem("QuoteRef"))) %>' ToolTip="Click to view/edit certificate" ></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:TemplateColumn>
                            <ItemTemplate>
                                <asp:Label ID="lblDate" runat="server" Text='<%# "Created - " + CStr(Container.DataItem("DateCreated").ToString)%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                    </Columns>
                </asp:DataGrid>
            </td>
        </tr>
    </table>
</ItemTemplate>

And in the code behind I have

    Public Sub DataGrid_EditItem(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)

    If e.CommandName = "RedirectToCert" Then

        Response.Redirect(e.CommandArgument.ToString)

    End If

End Sub

This is my latest attempt where I am trying to get the datagrids ItemCommand to fire when the client clicks on the link, but it's not working at the moment.

Failing this, is there an easier way to redirect the client to the correct page when they click on the linkbutton? I tried using the OnPostBackURL but the issue is that there are objects that need to be carried over that dont seem to be when I do this or when I just use a hyperlink with navigateurl set.

Thanks in advance for any help, this has had me stumped for 2 days straight.

A: 

I never managed to get the event handler to fire off of the linkbutton, but I did come up with a work around for the original problem, having variables passed from one page to another. I have used a hyperlink instead of a linkbutton, and used the query strings to pass reference numbers for the objects that I need to access on the new page.

Ryan French