这种情况该用枚举吗?

limii 2010-02-02 04:57:34
我做一个自定义控件,想给该控件一个属性,一个日期格式属性。这个属性值可以为以下三种之一:
YYYY-MM-DD, YYYY/MM/DD, YYYY.MM.DD。我本想用枚举来表示这三个可选属性,比如像下面这样定义:

public enum DateFormat{YYYY-MM-DD,YYYY.MM.DD,YYY/MM/DD}

但枚举值里面出现“-”之类的符号又不允许,我该怎么办?
...全文
222 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
limii 2010-02-03
  • 打赏
  • 举报
回复
up
limii 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 microdeviser 的回复:]
怎么可能这样定义enum呢
[/Quote]
我错了,等着帅锅的答案呐。
MicroDeviser 2010-02-02
  • 打赏
  • 举报
回复
怎么可能这样定义enum呢
limii 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 javak 的回复:]
引用 6 楼 limii 的回复:
引用 4 楼 zhujiazhi 的回复:
写个类,弄个静态变量
Class DataFormat
{
public const string format1 = "YYYY-MM-DD";
public const string format2 = "YYYY/MM/DD";
public const string format3 = "YYYY.MM.DD";
}

确是一个方法。不过试了还是没那个效果:就像其它的服务器控件的一个属性“Visible”,要设置这个属性时,它只提供“false”或者“true”让你选择,而不是随意填写其它文字。要实行这种效果是不是只能用枚举?


也是一样的效果啊!
[/Quote]
怎么定义这个属性呢?我是这样做的,但用的时候去不提示那三个值,只能自己填:

public class DateFormat
{
public const string format1 = "YYYY-MM-DD";
public const string format2 = "YYYY.MM.DD";
public const string format3 = "YYYY/MM/DD";
}
private DateFormat format;
public DateFormat Format
{
get { return this.format; }
set { this.format = value; }
}

JavaK 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 limii 的回复:]
引用 4 楼 zhujiazhi 的回复:
写个类,弄个静态变量
Class DataFormat
{
public const string format1 = "YYYY-MM-DD";
public const string format2 = "YYYY/MM/DD";
public const string format3 = "YYYY.MM.DD";
}

确是一个方法。不过试了还是没那个效果:就像其它的服务器控件的一个属性“Visible”,要设置这个属性时,它只提供“false”或者“true”让你选择,而不是随意填写其它文字。要实行这种效果是不是只能用枚举?
[/Quote]

也是一样的效果啊!
limii 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhujiazhi 的回复:]
写个类,弄个静态变量
Class DataFormat
{
public const string format1 = "YYYY-MM-DD";
public const string format2 = "YYYY/MM/DD";
public const string format3 = "YYYY.MM.DD";
}
[/Quote]
确是一个方法。不过试了还是没那个效果:就像其它的服务器控件的一个属性“Visible”,要设置这个属性时,它只提供“false”或者“true”让你选择,而不是随意填写其它文字。要实行这种效果是不是只能用枚举?
limii 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 bodytrtd 的回复:]
<%
      Dim Action,TitleId,ImageID,score
ImageID=(Request("TitleId"))
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from nt_score"
rs.open sql,conn,1,3
if rs("imageid")=ImageID  then
%>
<form action="" method="post">
<table width="980" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="143" height="38">图片id:
      <input name="id1" type="text" size="10"  value=" <%=request("titleID")%>"/> </td>
    <td width="103"> <span class="STYLE2">*图片id不可以改1 </span> </td>
    <td width="135">张数:
      <input name="zs1" type="text" size="10"  value=" <%=request("count")%>"/> </td>
    <td width="139"> <span class="STYLE2">*图片张数不可以改1 </span> </td>
    <td width="142">得分:
      <input name="score1" type="text" size="10"  value=""/> </td>
    <td width="318"> <span class="STYLE2">*100分以上为精华图片,如果取消精华的话,填写100以下1 </span> </td>
  </tr>
  <tr>
    <td colspan="6" align="center"> <input type="submit" name="Submit" value="修改" /> </td>
    </tr>
</table> </form>
<%else%>
<form action="" method="post">
<table width="980" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="143" height="38">图片id:
      <input name="id2" type="text" size="10"  value=" <%=request("titleID")%>"/> </td>
    <td width="103"> <span class="STYLE2">*图片id不可以改2 </span> </td>
    <td width="121">张数: <input name="zs2" type="text" size="10"  value=" <%=request("count")%>"/> </td>
    <td width="110"> <span class="STYLE2">*图片张数不可以改2 </span> </td>
    <td width="130">得分: <input name="score2" type="text" size="10"  value=""/> </td>
    <td width="373"> <span class="STYLE2">*100分以上为精华图片,如果取消精华的话,填写100以下2 </span> </td>
  </tr>
  <tr>
    <td colspan="6" align="center"> <input type="submit" name="Submit" value="修改" /> </td>
    </tr>
</table> </form>
<%rs.movenext
end if
rs.close
Set rs=Nothing
%>
{当rs("imageid")=ImageID应该显示第1个表格,当rs("imageid") <>ImageID应该显示第2个表格}但是现在都是只显示第2个表格的,,帮忙。。谢谢
[/Quote]
这位老兄,我是来这里讨饭的,没想到遇着你这个同行,还串错了地方。我不好意思得很,不能给你你要我给你的,你赶紧挪个窝的好哦
zhujiazhi 2010-02-02
  • 打赏
  • 举报
回复
写个类,弄个静态变量
Class DataFormat
{
public const string format1 = "YYYY-MM-DD";
public const string format2 = "YYYY/MM/DD";
public const string format3 = "YYYY.MM.DD";
}
绝代坏坏 2010-02-02
  • 打赏
  • 举报
回复
用转义符试试
bodytrtd 2010-02-02
  • 打赏
  • 举报
回复
<%
Dim Action,TitleId,ImageID,score
ImageID=(Request("TitleId"))
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from nt_score"
rs.open sql,conn,1,3
if rs("imageid")=ImageID then
%>
<form action="" method="post">
<table width="980" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="143" height="38">图片id:
<input name="id1" type="text" size="10" value="<%=request("titleID")%>"/></td>
<td width="103"><span class="STYLE2">*图片id不可以改1</span></td>
<td width="135">张数:
<input name="zs1" type="text" size="10" value="<%=request("count")%>"/></td>
<td width="139"><span class="STYLE2">*图片张数不可以改1</span></td>
<td width="142">得分:
<input name="score1" type="text" size="10" value=""/></td>
<td width="318"><span class="STYLE2">*100分以上为精华图片,如果取消精华的话,填写100以下1</span></td>
</tr>
<tr>
<td colspan="6" align="center"><input type="submit" name="Submit" value="修改" /></td>
</tr>
</table></form>
<%else%>
<form action="" method="post">
<table width="980" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="143" height="38">图片id:
<input name="id2" type="text" size="10" value="<%=request("titleID")%>"/></td>
<td width="103"><span class="STYLE2">*图片id不可以改2</span></td>
<td width="121">张数:<input name="zs2" type="text" size="10" value="<%=request("count")%>"/></td>
<td width="110"><span class="STYLE2">*图片张数不可以改2</span></td>
<td width="130">得分:<input name="score2" type="text" size="10" value=""/></td>
<td width="373"><span class="STYLE2">*100分以上为精华图片,如果取消精华的话,填写100以下2</span></td>
</tr>
<tr>
<td colspan="6" align="center"><input type="submit" name="Submit" value="修改" /></td>
</tr>
</table></form>
<%rs.movenext
end if
rs.close
Set rs=Nothing
%>
{当rs("imageid")=ImageID应该显示第1个表格,当rs("imageid")<>ImageID应该显示第2个表格}但是现在都是只显示第2个表格的,,帮忙。。谢谢
limii 2010-02-02
  • 打赏
  • 举报
回复
up

62,265

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧