【问题标题】:How to add placeholder to c# code?如何在 C# 代码中添加占位符?
【发布时间】:2015-10-21 06:26:21
【问题描述】:

如何在 c# 代码中添加占位符?我想以我的形式显示 DateTime.Now。

<div class="col-md-10">
  @Html.EditorFor(model => model.Date,  new { htmlAttributes = new { @class = "form-control"  } })
  @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
</div>

【问题讨论】:

    标签: c# placeholder 10gen-csharp-driver


    【解决方案1】:

    你试过了 -

      @Html.EditorFor(model => model.Date, new { placeholder =  DateTime.Now.ToString("MM/dd/yyyy")})
    

    【讨论】:

      【解决方案2】:
      /** Here is how I did it in my code. I had a richtexBox5 that I needed to add QTY placeholder. So what did was, inside public form i did the following */
        public Form1()
              {
                  InitializeComponent();
      
               richTextBox5.Text = "QTY";// set text you want to show
      
               if (richTextBox5.Text == "QTY")
                  {
                   richTextBox5.ForeColor = Color.LightGray;// set color
                 }
              }
      
      /**now make this function which will listen to mouse click  in wherever part you want*/
       private void richTextBox5_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
              {           
                  if(richTextBox5.Text=="QTY") // check what is in that textbox
                  {
                      richTextBox5.Text = "";// set it to null 
                      richTextBox5.ForeColor = Color.Black;// change color
                  }      
              }
      

      【讨论】:

      • 请描述您提出的解决方案。
      • 我确实在我的 cmets 中解释了自己。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 2017-07-31
      • 2019-03-27
      • 1970-01-01
      • 2015-01-23
      • 2016-04-05
      相关资源
      最近更新 更多