Click here to Skip to main content
15,868,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

As we can can have our own field text as Column Header using HeaderTemplate in gridview how can i do this in detailsview because i dont want to show the headers of the rows in a short format as available in the database table, they should be in a proper text format.Please Help.Thank You

here is my aspx code -
ASP.NET
<asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4"         ForeColor="#333333" GridLines="None" Width="500px" Height="400px">
            <footerstyle backcolor="#1C5E55" font-bold="True" forecolor="White" />
            <commandrowstyle backcolor="#C5BBAF" font-bold="True" />
            <rowstyle backcolor="#E3EAEB" />
            <fieldheaderstyle backcolor="#D0D0D0" font-bold="True" />
            <pagerstyle backcolor="#666666" forecolor="White" horizontalalign="Center" />
        <emptydatatemplate>
           No Data Found
        </emptydatatemplate>        
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" VerticalAlign="Middle" 
                ForeColor="White" />
        <HeaderTemplate>Personal Details</HeaderTemplate>        
            <editrowstyle backcolor="#7C6F57" />
            <alternatingrowstyle backcolor="White" />

and here is the fields of the table :
HTML
policy_no,fulname,dob,age,gender,nationality,brthplace,email,phno,height,weight,
caddress,paddress

I don't want to display them as shown in the fields of the table.
Posted
Updated 11-Oct-12 23:52pm
v3
Comments
I.explore.code 12-Oct-12 4:03am    
can you post your code/markup?
Member 9497070 12-Oct-12 4:47am    
where should i post my code? in comments?
DaveAuld 12-Oct-12 4:58am    
No, you use the Improve Question to edit and add your code to the original question.
AshishChaudha 12-Oct-12 4:51am    
Have you tried something??? I didn't understand "headers of the rows in a short format"
Member 9497070 12-Oct-12 5:11am    
I mean to say that the header of the row is displayed as the field name specified in the database table like in table it is policy_no and i want to show this as Policy No. in the detailsview.As we can do it in gridview using HeaderTemplate.

Try the below gridview
C#
<asp:gridview id="productGridView" runat="server" autogeneratecolumns="False" borderwidth="1px" backcolor="#DEBA84" cellpadding="3" cellspacing="2" borderstyle="None" xmlns:asp="#unknown">
<HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#A55129"></HeaderStyle>
    <columns>
        <asp:boundfield headertext="Policy No" insertvisible="False" datafield="policy_no">
              <itemstyle horizontalalign="Center"></itemstyle>
        </asp:boundfield>
        <asp:boundfield headertext="Name" datafield="fulname">
        </asp:boundfield>
        <asp:boundfield headertext="Date of Birth" datafield="dob">
        </asp:boundfield>
    </columns>
</asp:gridview>


You can more coustmize this as per your need.


For more info refer the MSDN site .Here[^]
 
Share this answer
 
Comments
Member 9497070 12-Oct-12 7:19am    
I have already tried it sir but using gridview data is shown in table format and i want to show one row at a time so i thought it will be good to use detailsview. Sir i am a fresher thats why having so many problems.
Member 9497070 19-Oct-12 7:14am    
Thnx to u sir
Mohd. Mukhtar 19-Oct-12 8:04am    
No Problem
For this problem we just have to bind the datasource and then in the design we have to code as follows-

XML
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px">
 <fields>
            <asp:boundfield datafield="policy_no" headertext="Policy No." xmlns:asp="#unknown">
                InsertVisible="False"/>
            <asp:boundfield datafield="fulname" headertext="Full Name">
                InsertVisible="False"/>
            <asp:boundfield datafield="dob" headertext="Date of Birth">
                InsertVisible="False"/>
    </asp:DetailsView></asp:boundfield></asp:boundfield></asp:boundfield></fields>


where DataField contains field from the database table and HeaderText contains our text for the field which we want to display.Using this we can solve the problem.The code is somewhat like Gridview as we can see in the previous solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900