**** 关于Dropdownlist的小问题 ****(我出手从来就是100分)

suncode 2004-05-06 12:20:47
我想用一个Dropdownlist显示月份的下拉,动态加入如下:

for (int i=1;i<= 12; i++)
{
this.Month.Items.Add(i.ToString());
}
但下拉 的显示只有1,2,3。。。12的数字显示, 我想达到如下的HTML效果:

<asp:listitem value="1">January</asp:listitem>
<asp:listitem value="2">Feburary</asp:listitem>
<asp:listitem value="3">March</asp:listitem>
。。。。。。
<asp:listitem value="12">December</asp:listitem>

也就是显示的下拉是January,。。。December的文字, 而 value=中仍然用1,2,3。。。12 的值

谢谢!
...全文
45 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2004-05-06
  • 打赏
  • 举报
回复
sorry,有个地方(构造函数)写错了

//定义一个DropDownListData类
public class DropDownListData
{
private string _text;
private string _value;

public DropDownListData(string newText, string newValue)
{
_text = newText;
_value = newValue;
}

public string Text
{
get { return _text;}
set { _text = value;}
}

public string Value
{
get { return _value ; }
set { _value = value; }
}
}

//帮定数据
ArrayList DropDownListDatas= new ArrayList();

DropDownListDatas.Add(new DropDownListData("January", "1" ));
...
DropDownList1.DataSource = DropDownListDatas;
DropDownList1.DataBind();
lxcc 2004-05-06
  • 打赏
  • 举报
回复
//定义一个DropDownListData类
public class DropDownListData
{
private string _text;
private string _value;

public TabItem(string newText, string newValue)
{
_text = newText;
_value = newValue;
}

public string Text
{
get { return _text;}
set { _text = value;}
}

public string Value
{
get { return _value ; }
set { _value = value; }
}
}

//帮定数据
ArrayList DropDownListDatas= new ArrayList();

DropDownListDatas.Add(new DropDownListData("January", "1" ));
...
DropDownList1.DataSource = DropDownListDatas;
DropDownList1.DataBind();
bitsbird 2004-05-06
  • 打赏
  • 举报
回复
接分:)
zhougangnj 2004-05-06
  • 打赏
  • 举报
回复
this.Month.Items.Add(new ListItem("January","1")
suncode 2004-05-06
  • 打赏
  • 举报
回复
每次都满意而归! 谢谢。 参加的都有份
bitm 2004-05-06
  • 打赏
  • 举报
回复
学习
cuike519 2004-05-06
  • 打赏
  • 举报
回复
上面的方法中...为省略其中其他的月份,你在使用的时候必须一个一个添加上去!
cuike519 2004-05-06
  • 打赏
  • 举报
回复
string[] strMonth = new string[]{"January","Feburary",..."December"};
for (int i=1;i<= 12; i++)
{
ListItem item = new ListItem(strMonth[i],i);
this.Month.Items.Add(item);
}

62,243

社区成员

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

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

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

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