如何设置属性网格项的最大长度 [英] How do I set maximuml length of property grid item

查看:82
本文介绍了如何设置属性网格项的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Category(All)]
       [StringLength(40)]
       [DisplayName(ITEMNAME)]
       [XmlAttribute]
       public override string Label
       {
           get
           {
               return base.Label;
           }
           set
           {

               value = value.TrimEnd();   ignorieren


               if (value.length > 40)
               {
                //here I want a user not to allow to write more than 40 char
                  when user write something in  Name feild max Length 40 i want a user to allow

               }


           }
       }



这是我的ITEMNAME属性网格视图的代码我想要的值不应该超过40,最大值是40所以我想做的是当用户输入av时alue grater比40想要使属性feild禁用,以便用户可以#t输入更多。

经过研究我发现了一个stringLength属性(System.ComponentModel.DataAnnotations)但它似乎没有任何帮助我在这个或者thete是解决这个问题的另一种方法吗?


This is my code for Property grid view for ITEMNAME i want that value should not be longer han 40 , max value is 40 so what i want to do is that when user enter a value grater than 40 want to make property feild disabled so that user can#t enter more.
After researching i found a stringLength attribute(System.ComponentModel.DataAnnotations) but its seems to be not working anyone help me in this or thete is another way to solve This ???????????

推荐答案

它是mvc还是标准网页表单?



System.ComponentModel.DataAnnotations用于MVC

ex:

it's mvc or standard web forms ?

System.ComponentModel.DataAnnotations is used with MVC
ex :
public class User
{
    [Required(ErrorMessage = "Name is required.")]
    [MaxLength(40, ErrorMessage = "Name cannot be longer than 40 characters.")]
    public string Name { get; set; }
}





网页表格你可以使用正则表达式验证器



with web forms you can use regex validator

<asp:RegularExpressionValidator runat="server" ID="valInput"

    ControlToValidate="txtInput"

    ValidationExpression="^[\s\S]{0,40}




ErrorMessage = 请输入最多40个字符

显示 = 动态 > * < / asp:RegularExpressionValidator >
" ErrorMessage="Please enter a maximum of 40characters" Display="Dynamic">*</asp:RegularExpressionValidator>





如果它只是你需要截断的显示你可以使用css和省略号



if it is only the display that you need to truncate you can use css and ellipsis

.truncate {
  width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


用于Windo ws表单应用程序我正在使用.Net 3.5但它不支持MaxLength属性我添加了.dll并使用System.ComponentModel.DataAnnotations
its for Windows Form Application i am working with .Net 3.5 but its not supporting MaxLength attribute i have added .dll and using System.ComponentModel.DataAnnotations


这篇关于如何设置属性网格项的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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