<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="testPageLoad.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="c#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack){
for(int i=0; i<4; i++)
{
DateTime date=DateTime.Today+ new TimeSpan(i, 0, 0, 0);
DropDownList1.Items.Add(date.ToString("MM dd, yyyy"));
DropDownList1.Items.Add(i.ToString());//这里的Add方法都不能用,
                                                         //不知道为什么,有没有替代的方法?
}
}
}

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="冼极">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 272px; POSITION: absolute; TOP: 144px" runat="server" Width="176px" Height="24px">
<asp:ListItem text="Oct,18,2005" runat="server" />
</asp:DropDownList>

    </FONT>
</form>
</body>
</HTML>DropDownList1.Items.Add(date.ToString("MM dd, yyyy"));
DropDownList1.Items.Add(i.ToString());//这里的Add方法都不能用,
                                     //不知道为什么,有没有替代的方法?我用了这个方法依然显示没有绑定items!
如果解决,马上给分

解决方案 »

  1.   

    if(!IsPostBack)改为
    if(!Page.IsPostBack)
    试试
      

  2.   

    if(!Page.IsPostBack)
    我一般是調存儲過程,動態顯示
    DropDownList1.DataBind();
      

  3.   

    DropDownList1.Items.Add(new ListItem(i.ToString()))
      

  4.   

    <asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 272px; POSITION: absolute; TOP: 144px" runat="server" Width="176px" Height="24px">
    <asp:ListItem text="Oct,18,2005" runat="server" />//这行去掉看看
    </asp:DropDownList>
      

  5.   

    DropDownList1.Items.Add(date.ToString("MM dd, yyyy"),date.ToString("MM dd, yyyy"));
    试试看
      

  6.   

    Compiler Error Message: CS1501: No overload for method 'Add' takes '2' argumentsSource Error: Line 25:         //DropDownList1.Bind();
    Line 26:        DateTime date=DateTime.Today+new TimeSpan(i, 0, 0, 0);
    Line 27:        DropDownList1.Items.Add(date.ToString("MM DD, yyyy"),date.ToString("MM DD, yyyy"));
     
      

  7.   

    DropDownList1.Items.Add(new ListItme(date.ToString("MM dd, yyyy"),date.ToString("MM dd, yyyy")));
    试试
      

  8.   

    错了
    是DropDownList1.Items.Add(new ListItem(date.ToString("MM dd, yyyy"),date.ToString("MM dd, yyyy")));
      

  9.   

    <script language="c#" runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
    if(!IsPostBack){
    for(int i=0; i<4; i++)
    {
    DateTime date=DateTime.Today+ new TimeSpan(i, 0, 0, 0);
             ListItem itm = new ListItem(date.ToString(),i.ToString());
                      DropDownList.Item.Add(itm);
    }
    }
      这样应该是可以的
      

  10.   

    ....
    你换一个其他的浏览器,譬如腾讯的TT
    在.net环境下编译之后再到TT下运行....
    呵呵....
      

  11.   

    DropDownList1.Items.Add(new ListItem(date.ToString(),i.ToString());试
      

  12.   

    同意:  回复人: juziE2006(橘子)  里面是new ListItem()