Solved

Need to rename Grid column names in a Dynamic Data website

Posted on 2011-03-21
11
571 Views
Last Modified: 2012-06-21
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.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 6
  • 4
11 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35181899
Hi,

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
0
 

Author Comment

by:newbieweb
ID: 35182080
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...
0
 

Author Comment

by:newbieweb
ID: 35182133
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?

newbieweb
0
 
LVL 7

Expert Comment

by:nbove
ID: 35182319
If you are looking for an event that will fire every time there is a postback, the Gridview PreRender should do the trick.
0
 

Author Comment

by:newbieweb
ID: 35182796
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?

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 7

Expert Comment

by:nbove
ID: 35183705
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";
}
0
 

Author Comment

by:newbieweb
ID: 35184451
I had been doing so successfully, but only in pages inheriting from:
System.Web.DynamicData.EntityTemplateUserControl

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

I am stumped!

newbieweb

0
 
LVL 7

Expert Comment

by:nbove
ID: 35184714
Hmm, perhaps I am not understanding the nature of the problem.  If there is not an event handler, then simply add the event handler.
0
 

Author Comment

by:newbieweb
ID: 35189383
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>

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

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

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <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">
                <ItemTemplate>
                    <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?");' />
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
                <EmptyDataTemplate>
                    <div class="DDNoItem">No such item.</div>
                </EmptyDataTemplate>
            </asp:FormView>

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

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

            <br />

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

Open in new window

0
 
LVL 7

Accepted Solution

by:
nbove earned 500 total points
ID: 35190803
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.
0
 

Author Closing Comment

by:newbieweb
ID: 35215302
Thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now