Need to rename Grid column names in a Dynamic Data website

I have created a table which maps column names to the display names we want Dynamic Data to show. And I have succeeded in a few cases, like the Details page, getting the display name inserted and shown by Dynamic Data. But when it comes to the List.aspx page, the Label_PreRender() event only deals with relations, and does not fire when a column is being created.

Can anyone give me some advice? This page inherits from System.Web.UI.Page, and I need to find how to overwrite the column names.

newbiewebSr. Software EngineerAsked:
Who is Participating?
Nathan BoveConnect With a Mentor Software EngineerCommented:
It looks as though you are creating all of your controls using custom user controls.  You will have to find the spot in the code that is creating the label and add an event handler to the label's prerender event when it is created.
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:

Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
e.Row.Cells(1).Text = “Show me the money”
End If
End Sub
newbiewebSr. Software EngineerAuthor Commented:
I do C#, but any time I have tried to change the DisplayName I have found them to be read only. I will try to decifer what you'd described...
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

newbiewebSr. Software EngineerAuthor Commented:
I found the GridView1_RowCreated() event and added the code in C#, but it does not stop at a breakpoint in that event. I need an event that will fire each and every time the Grid is populated. Do you know that one?

Nathan BoveSoftware EngineerCommented:
If you are looking for an event that will fire every time there is a postback, the Gridview PreRender should do the trick.
newbiewebSr. Software EngineerAuthor Commented:
I think I found the problem:

<asp:Label runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" />

What does this line tell you about what inside of Label_PreRender that I need to change with the correct display name?

Nathan BoveSoftware EngineerCommented:
Ahh, I see what you are saying.

Try adding this to code to your "Label_PreRender" event handler:

protected void Label_PreRender(object sender, EventArgs e) {
  Label lbl = (Label)sender;
  lbl.Text = "New Display Name";
newbiewebSr. Software EngineerAuthor Commented:
I had been doing so successfully, but only in pages inheriting from:

When I inherit from  System.Web.UI.Page I can not do the above, since there is no Label_PreRender event.

I am stumped!


Nathan BoveSoftware EngineerCommented:
Hmm, perhaps I am not understanding the nature of the problem.  If there is not an event handler, then simply add the event handler.
newbiewebSr. Software EngineerAuthor Commented:
How do I associate the Label_PreRender event with the label? I see no label in the entire page.

<asp:Content ID="headContent" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
            <asp:DataControlReference ControlID="FormView1" />

    <h2 class="DDSubHeader">Entry from table <%= /*table.DisplayName*/ Title %></h2>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                HeaderText="List of validation errors" CssClass="DDValidator" />
            <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" />

            <asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" OnItemDeleted="FormView1_ItemDeleted" RenderOuterTable="false">
                    <table id="detailsTable" class="DDDetailsTable" cellpadding="6">
                        <asp:DynamicEntity runat="server" />
                        <tr class="td">
                            <td colspan="2">
                                <asp:DynamicHyperLink runat="server" Action="Edit" Text="Edit" />
                                <asp:LinkButton runat="server" CommandName="Delete" Text="Delete"
                                    OnClientClick='return confirm("Are you sure you want to delete this item?");' />
                    <div class="DDNoItem">No such item.</div>

            <asp:EntityDataSource ID="DetailsDataSource" runat="server" EnableDelete="true" />

            <asp:QueryExtender TargetControlID="DetailsDataSource" ID="DetailsQueryExtender" runat="server">
                <asp:DynamicRouteExpression />

            <br />

            <div class="DDBottomHyperLink">
                <asp:DynamicHyperLink ID="ListHyperLink" runat="server" Action="List">Show all items</asp:DynamicHyperLink>

Open in new window

newbiewebSr. Software EngineerAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.