在DetailsView中对数据库表以外的其他字段使用我自己的文本时出现问题 [英] Problem in having my own text for the fields other than of database table in detailsview

查看:68
本文介绍了在DetailsView中对数据库表以外的其他字段使用我自己的文本时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

因为我们可以在gridview中使用HeaderTemplate将自己的字段文本用作Column Header,所以我可以在detailsview中执行此操作,因为我不想以数据库表中可用的短格式显示行的标题,因此它们应该位于正确的文本格式.请帮助.谢谢

这是我的aspx代码-

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: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 :

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.

推荐答案

尝试下面的gridview
Try the below gridview
<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>



您可以根据需要更轻松地做到这一点.


有关更多信息,请参考MSDN网站.此处 [



You can more coustmize this as per your need.


For more info refer the MSDN site .Here[^]


对于这个问题,我们只有绑定数据源,然后在设计中我们必须编写如下代码-

For this problem we just have to bind the datasource and then in the design we have to code as follows-

<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>



其中的DataField包含数据库表中的字段,而HeaderText包含我们要显示的字段的文本.使用此方法,我们可以解决问题.代码类似于Gridview,就像在上一个解决方案中看到的一样.



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.


这篇关于在DetailsView中对数据库表以外的其他字段使用我自己的文本时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆