显示gridview的最后4位数字 [英] show last 4 digits in gridview

查看:168
本文介绍了显示gridview的最后4位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net GridView和具有数字例如列1234567,我想说明的最后4位数字,像这样xxx4567。这是可能的。

我是我的GridView控件绑定到如下的对象的列表:

 列表<详情> objdet = Manager.Get_Details(ID);             如果(objdet!= NULL)
             {                 gvDetails.DataSource = objdet;
                 gvDetails.DataBind();
             }

在我的网,我有这样的:

 < ASP:GridView控件ID =gvDetails=服务器AllowPaging =真
                AllowSorting =真的AutoGenerateColumns =false的网格线=无的CssClass =MGRID>
                <柱体和GT;
                < ASP:BoundField的数据字段=DetNumber的HeaderText =号码只读=真/>
< /专栏>
            < / ASP:GridView的>


解决方案

在您的详细信息对象,添加另一个属性调用类似 NumberWithMask

 公共const int的NumberWithMaskLength = 4;公共字符串DetNumber {搞定;组; }公共字符串NumberWithMask
{
    得到
    {
        如果(string.IsNullOrEmpty(DetNumber)及!&安培; DetNumber.Length> NumberWithMaskLength)
        {
            返回新的字符串(X,DetNumber.Length - NumberWithMaskLength)+ DetNumber.Substring(DetNumber.Length - NumberWithMaskLength);
        }
        返回的String.Empty;
    }
}

然后用在相关新领域的BoundField

 < ASP:BoundField的数据字段=NumberWithMask的HeaderText =号码只读=真/>

I have an asp.net gridview and a column that has digits e.g. 1234567, I want to show the last 4 digits like so xxx4567. Is this possible.

I am binding my gridview to a list of objects as below:

List<Details> objdet = Manager.Get_Details(ID);

             if (objdet!= null)
             {

                 gvDetails.DataSource = objdet;
                 gvDetails.DataBind();
             }

and in my grid i have this:

 <asp:GridView ID="gvDetails" runat="server" AllowPaging ="true" 
                AllowSorting ="true" AutoGenerateColumns="false" GridLines="None" CssClass="mGrid">
                <Columns>
                <asp:BoundField DataField="DetNumber" HeaderText="Number" ReadOnly="true" />
</Columns>
            </asp:GridView>

解决方案

In your Details object, add another Property called something like NumberWithMask:

public const int NumberWithMaskLength = 4;

public string DetNumber { get; set; }

public string NumberWithMask
{
    get
    {
        if (!string.IsNullOrEmpty(DetNumber) && DetNumber.Length > NumberWithMaskLength)
        {
            return new string('x', DetNumber.Length - NumberWithMaskLength ) + DetNumber.Substring(DetNumber.Length - NumberWithMaskLength );
        }
        return string.Empty;
    }
} 

Then use the new field in the relevant BoundField:

<asp:BoundField DataField="NumberWithMask" HeaderText="Number" ReadOnly="true" /> 

这篇关于显示gridview的最后4位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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