Changing the text of the links in the command column

Last post 10-23-2009 6:38 AM by ed_ward_graham. 4 replies.

Sort Posts:

  • Changing the text of the links in the command column

    10-22-2009, 6:38 AM

    I have a gridview with just the Select link showing in the command column; I would like to change the text to say "View details" instead of "Select".  Nothing more, just that!

    I have read Steve's blog entry about using IAutoFieldGenerator (http://csharpbits.notaclue.net/2009/05/move-command-link-column-to-end-column.html) and appreciate that this will probably work, although I didn't really understand it.  I'm just wondering if there's a simpler way if all I want to do is change the text of the link.  (I tried manipulating the gridview cell directly in the OnRowDataBound event but the actual control containing the link is inaccessible.)

    Cheers,

    Ed Graham


  • Re: Changing the text of the links in the command column

    10-22-2009, 11:27 AM
    • Participant
      785 point Participant
    • DaveRuss
    • Member since 02-16-2009, 9:24 AM
    • Cambridgeshire
    • Posts 169

    Change the grid properties to have AutoGenerateSelectButton = "false"

    Add a <Columns> tag for the grid

    Within the <Columns> tag, add an <asp:TemplateColumn>

    with...

    <a href="<%# table.GetActionPath(PageAction.List, GetDataItem()) %>">View Details</a>


    ....or something very similar.

    Dave

  • Re: Changing the text of the links in the command column

    10-22-2009, 11:53 AM

    DaveRuss:

    Within the <Columns> tag, add an <asp:TemplateColumn>

    with...

    <a href="<%# table.GetActionPath(PageAction.List, GetDataItem()) %>">View Details</a>

    ....or something very similar.

    Thanks for that, Dave -- I have understated my lack of understanding a little.  I have added a TemplateField like so:

    <asp:TemplateField><ItemTemplate><a href="<%# Table.GetActionPath(PageAction.Details, Row) %>">View details</a></ItemTemplate></asp:TemplateField>

    (taken partly from Steve's post and partly from yours) but get the following error:

    'System.Web.UI.WebControls.Table' does not contain a definition for 'GetActionPath'

    I'm sure it's completely obvious to those who know ... !

  • Re: Changing the text of the links in the command column

    10-23-2009, 3:43 AM
    • Participant
      785 point Participant
    • DaveRuss
    • Member since 02-16-2009, 9:24 AM
    • Cambridgeshire
    • Posts 169

    Is your grid on one of the DyamicData PageTemplate pages or is on your own asp.net page?

    If it's on your own page, is it registered with DynamicDataManager?

    What DataSource are you using?

    Dave

  • Re: Changing the text of the links in the command column

    10-23-2009, 6:38 AM
    Answer

    DaveRuss:

    Is your grid on one of the DyamicData PageTemplate pages or is on your own asp.net page?

    If it's on your own page, is it registered with DynamicDataManager?

    What DataSource are you using?

    Dave

     

    Thanks for the reply, Dave.  It is an overridden version of the DD ListDetails.aspx page, in a top-level folder called "Paper proposals".  I believe it is registered with the DynamicDataManager; I simply copied the original ASPX file and changed the bits I needed to change. 

    I've actually managed to solve my problem now with the following event handler for OnRowDataBound:

        protected void OnGridViewRowDataBound(object sender, GridViewRowEventArgs e)
        {
            foreach (Control c in e.Row.Cells[0].Controls) 
            {
                if (c is LinkButton) 
                {
                    LinkButton btn = (LinkButton)c;
                    if (btn.CommandName == DataControlCommands.SelectCommandName)
                    {
                        btn.Text = "View details";
                    }
                }
            }
        }
    


     

Page 1 of 1 (5 items)