1

I have been trying to make hyperlinks in my gridview to work, but I can't seem to. The main problem is that simply clicking on the hyperlinks does nothing. Absolutely nothing at all. The reason for my hyperlinks is that when records are displayed in my gridview, the hyperlinks would allow the user to redirect to my Edit page to edit the selected record. My gridview gets data from an ObjectDataSource, which then calls a stored procedure in my database to execute a query string. TxnID is one of the many columns involved in the query string.

code for hyperlink:

<asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <asp:HyperLink ID="hlEditTxn" NavigateUrl='<% Eval("TxnID", "~/FXTxnEdit.aspx?TxnID={0}") %>'
                        Text="Edit" runat="server" ></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>

code for Edit page:

public partial class FXTxnEdit : System.Web.UI.Page
{
    TransactionHandler txnHnd = null;
    MainFunctions mf = null;
    int TransactionID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {

            string id = Request.QueryString["TxnID"] as string;

            if (id == null)
            {
                Response.Redirect("Default.aspx");
            }

For some reason, this does not work. I have tried inserting a Label column in my gridview that displays the TxnID, just to make sure if the ObjectDataSource does get the TxnID:

<asp:TemplateField HeaderText="TxnID">
                <ItemTemplate>
                    <asp:Label ID="lblTxnID" runat="server" Text='<%# Eval("TxnID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

It does get the TxnID, and it does display the TxnID in the gridview, which is good.

Any ideas on what could be wrong? or what else needs to be done or could be done to make the hyperlinks work?

2
  • 1
    What do you mean by "the hyperlinks dont work"? Are the links not appearing at all? Are they not clickable? Are they not redirecting to the page FXTxnEdit.aspx? Commented Dec 13, 2013 at 8:31
  • clicking the hyperlinks simply does nothing Commented Dec 13, 2013 at 8:39

3 Answers 3

1

Change the links declaration and the binding expression to the following:

<asp:HyperLink ID="hlEditTxn" NavigateUrl='<%# "~/FXTxnEdit.aspx?TxnID=" + Eval("TxnID") %>'
                    Text="Edit" runat="server" ></asp:HyperLink>

give it a shot and let me know it goes

Leo

Sign up to request clarification or add additional context in comments.

1 Comment

after solving my own problem, I tried your code. It works too
1

wow. managed to solve my VERY BIG problem, after more than 5 friggin hours XD

if you will look closely at the Hyperlink declaration in my question:

<asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:HyperLink ID="hlEditTxn" NavigateUrl='<% Eval("TxnID", "~/FXTxnEdit.aspx?TxnID={0}") %>'
                    Text="Edit" runat="server" ></asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>

you'll see that there is no number sign/hash (#) right before the Eval. I completely missed that one. Once I added that miniscule character to my code...

NavigateUrl='<%# Eval("TxnID", "~/FXTxnEdit.aspx?TxnID={0}") %>'

everything works wonders now. Coding is a bee-otch. Can make you look extremely dumb sometimes LOL

P.S. @Leo - your solution works BTW, I tried it.

side question, what is the # for? what does it mean?

Comments

0

why don't you try this

<asp:HyperLink ID="hlEditTxn" NavigateUrl='<%# string.Format("~/FXTxnEdit.aspx?TxnID={0}",Eval("TxnID"))%>'
                    Text="Edit" runat="server" ></asp:HyperLink>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.