0

私はasp.netとc#が初めてです。現在のページ タイトルを表示するようにドロップダウン リスト ボックスにテキストを設定しようとしていますが、うまくいきません。以下のコードに基づいて、それを行う方法について誰かがアドバイスできますか? ありがとう!

    if (!Page.IsPostBack)
    {
        string path = @"C:\Websites\TaxMapCS";
        DirectoryInfo di = new DirectoryInfo(path);
        FileSystemInfo[] fi = di.GetFiles("*.aspx");
        var result = string.Join(",", fi.OrderByDescending(f => f.CreationTime).Select(i => i.ToString()).ToArray());

        DropDownList1.DataSource = result.Replace(".aspx", "").Split(',');

        DropDownList1.DataBind();

        DropDownList1.Items.Insert(0, new ListItem("Select Edition", ""));

    }
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Redirect(DropDownList1.SelectedItem.Value + ".aspx");
}
4

4 に答える 4

2

これを試して

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Redirect(DropDownList1.SelectedItem.Text + ".aspx");
}

または

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Redirect(DropDownList1.SelectedValue + ".aspx");
}
于 2013-07-24T19:15:49.970 に答える
0

ASP.NET についてはよくわかりませんが、通常の C# では、次のようなことを試すことができると思います。

DropDownList1.Items.Add(this.Page.Title);

コードを手伝ってくれた Cubicle.Jockey に感謝します。

于 2013-07-24T19:14:44.143 に答える
0

これを試して:

if (!Page.IsPostBack)
    {
        string path = @"C:\Websites\TaxMapCS";
        DirectoryInfo di = new DirectoryInfo(path);
        FileSystemInfo[] fi = di.GetFiles("*.aspx");
        var result = string.Join(",", fi.OrderByDescending(f => f.CreationTime).Select(i => i.ToString()).ToArray());

        DropDownList1.DataSource = result.Replace(".aspx", "").Split(',');

        DropDownList1.DataBind();

        DropDownList1.Items.Insert(0, new ListItem("Select Edition", ""));
        DropDownList1.Items.Insert(0, new ListItem(Page.Title, ""));

    }
}


    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(DropDownList1.SelectedIndex > 0)//do not redirect if 'Selected Edition' is selected
        {
            Response.Redirect(DropDownList1.SelectedItem.Text + ".aspx");
        }
    }
于 2013-07-24T21:49:22.630 に答える