Click here to Skip to main content
16,013,747 members
Articles / Web Development / HTML
Article

detailsview.TemplateField.FooterTemplate rendering problem for using it to appear in another language for detailsview

Rate me:
Please Sign up or sign in to vote.
2.75/5 (7 votes)
17 Jan 2007Ms-PL1 min read 45.2K   147   11   4
This code solves the problem of rendering detailsview.TemplateField.FooterTemplate

Sample Image - KareemCode1.jpg

Introduction

After a long search about why DetailsView.FieldTemplate.FooterTemplate is not rendered, I found out a way to generate it from scratch by modifying the HTML code that is generated by DotNet for the DetailsView control. I will explain it in the next steps.

Step 1

ASP.NET
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" 
    AutoGenerateRows="False"
    CellPadding="4" DataSourceID="ObjectDataSource1" 
    ForeColor="#333333" GridLines="None"Height="50px" 
    OnItemInserting="DetailsView1_ItemInserting" 
    OnItemUpdated="DetailsView1_ItemUpdated"
    Width="50%">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="Guid" HeaderText="$ID$" 
    InsertVisible="False" ReadOnly="True" />
<asp:TemplateField HeaderText="$Ÿéèí§$" InsertVisible="False">
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="$Name$" />
<asp:TemplateField HeaderText="$ŸéŸ«ê$"></asp:TemplateField>
<asp:BoundField DataField="Address" HeaderText="$Address$" />
<asp:TemplateField HeaderText="$ŸéãëíŸë$"></asp:TemplateField>
<asp:BoundField DataField="Email" HeaderText="$Email$" />
<asp:TemplateField HeaderText="$ŸéŸêïé ŸéŸé袩íëï$"></asp:TemplateField>
<asp:BoundField DataField="Tel" HeaderText="$Telephone$" />
<asp:TemplateField HeaderText="$Ÿé¢éïåíë$"></asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    DataObjectTypeName="Employee"
    InsertMethod="Add" SelectMethod="getAllEmplyees" 
    TypeName="Employee" UpdateMethod="Update">
</asp:ObjectDataSource>

The code above illustrates that when putting the fields of detailsview, I put them between two $ as if I have Field(Template Field,Bound Filed,.......) called (Name). I put its headerText property as $Name$, and added a new Template column for the Footer and put it between two $ as in the previous example but by using another language that I wanted to use.

Step 2

C#
public static void ApplyFooters(ref string str, DetailsView dv)
{
    for (int i = 0; i < dv.Fields.Count - 1; i += 2)
    {
        FooterTemplate.SetFooter(ref str, dv.Fields[i].HeaderText, 
            dv.Fields[i + 1].HeaderText, dv.ClientID);
 
    }
    FooterTemplate.AdjustGrid(ref str, dv.ClientID);
}

This function takes the HTML code as a ref string and takes the detailsview control as a parameter. The function loops on detailsView Control fields and uses the SetFooter parameter to generate the footer.

C#
private static void SetFooter(ref string str, string Header, 
                    string Footer, string GridName)
{
    int StartGridIndex = str.IndexOf(GridName);
    if (StartGridIndex == -1) return;
    int EndGridIndex = str.IndexOf("</table>", StartGridIndex);
    int HeaderIndex = str.IndexOf(Header);
    if (HeaderIndex == -1) return;
    int StartIndex = str.IndexOf("</tr>", HeaderIndex);
    if (StartIndex == -1 || (StartIndex < StartGridIndex || 
                StartIndex > EndGridIndex)) return;
    int EndIndex = str.IndexOf(">", StartIndex + 5);
 
    string oHeader = Header.Replace("$", "");
    string oFooter = Footer.Replace("$", "");
    str = str.Remove(StartIndex, (EndIndex - StartIndex) + 1);
    str = str.Remove(str.IndexOf(Footer) + Footer.Length + 5, 18);
    str = str.Insert(str.IndexOf(Footer) - 1, " align= right");
    str = str.Replace(Header, oHeader);
    str = str.Replace(Footer, oFooter);
}

This function takes fields one by one to generate its Footer template by converting the rendered HTML code of the Template Column that I added in the DetailsView Source Code.

C#
private static void AdjustGrid(ref string str, string GridName)
{
    int StartIndex = str.IndexOf(GridName);
    if (StartIndex == -1) return;
    int EndIndex = str.IndexOf("</table>", StartIndex);
    int ColIndex = str.IndexOf("<td colspan=\"2\">", StartIndex);
    if (ColIndex == -1) return;
    if (ColIndex < EndIndex)
    {
        str = str.Remove(ColIndex, 16);
        str = str.Insert(ColIndex, "<td colspan=\"3\">");
    }
    ColIndex = str.IndexOf("<td colspan=\"2\">", StartIndex);
    if (ColIndex == -1) return;
    if (ColIndex < EndIndex)
    {
        str = str.Remove(ColIndex, 16);
        str = str.Insert(ColIndex, "<td colspan=\"3\">");
    }
}

This function adjusts the general figure of detailsview because of the problems that result from the modifications to the rendered HTML code.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) alfanarIT
Egypt Egypt
I'm Kareem Ammer Solution developer @ AlfanarIT Company @ KSA,graduated from Faculty of Comupter And Information Helwan university, Information system department.

Comments and Discussions

 
QuestionI want to use multiple files per culture how can i...? Pin
Naveen Kumar M14-Jun-07 19:43
Naveen Kumar M14-Jun-07 19:43 
Hi Please help me out here!!!
I am developing a Multilingual applications using C# .For this implementation I am using .resx files per language and using Resourcemanager object I am getting values from those file.
Now my problem is here…
I do have more than 50000 records and in each .resx (per language).Then while trying to edit (.resx) files my system getting hanged up. So I am planning to split (.resx ) files into multiple files so that I can edit my key values easily.
My requirements:
I want to use multiple files per culture, But while using those I want to create only single object for resourcemanager. I don’t want get developer to confuse to find out which key in which file.
Please help me out here as early as possible!!!!!


Thanks
naveen m
AnswerRe: I want to use multiple files per culture how can i...? Pin
Kareem.Ammer17-Jul-07 3:12
Kareem.Ammer17-Jul-07 3:12 
Generalmore languages Pin
Tamer Yousry Tharwat20-Jan-07 21:54
Tamer Yousry Tharwat20-Jan-07 21:54 
GeneralRe: more languages Pin
Kareem.Ammer21-Jan-07 1:03
Kareem.Ammer21-Jan-07 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.