SelectedIndexChanged 过滤 ascx 控件

发布于 2024-10-16 03:21:07 字数 1263 浏览 2 评论 0原文

我使用数据绑定下拉列表来填充带有项目迭代的组合框,并使用 ascx 控件来显示标签云。我正在检索下拉列表的 selectedValue 并将其存储为会话以过滤掉标签云(对于整个项目或通过迭代)。我收到错误,因为我输入的默认值无法转换为整数。预先感谢您的帮助!

filteroptions.Items.Insert(0, "Entire Project");

ASP.NET 文件:

protected void filteroptions_SelectedIndexChanged(object sender, EventArgs e)
{
    string selected_iteration = filteroptions.SelectedValue;

    Session["iteration"] = selected_iteration;

}

ASCX 控制:

protected void Page_Load(object sender, EventArgs e)
{
    proj_name = Request.QueryString["project"].ToString();
    proj_id = Request.QueryString["id"].ToString();

    iteration = (string)Session["iteration"]; 

    BindTagCloud();

}

private void BindTagCloud()
{

    int pro_id = Convert.ToInt32(proj_id);
    int iteration_id = Convert.ToInt32(iteration);

 ....

 if (iteration_id != 0)
    {
        ListView1.DataSource = tagCloudNegativeIteration;
        ListView1.DataBind();

        ListView2.DataSource = tagCloudPositiveIteration;
        ListView2.DataBind();

    }
    else
    {
        ListView1.DataSource = tagCloudNegative;
        ListView1.DataBind();

        ListView2.DataSource = tagCloudPositive;
        ListView2.DataBind();

    }
}

I am using a databound dropdown list to populate a combobox with project iterations and an ascx control to display a tag cloud. I am retrieving the selectedValue of the dropdown and storing it as a session to filter out the tag cloud (for the entire project or by iteration). I am getting an error, because the default value which I have entered cannot be then converted to an integer. Thanks in advance for your help!

filteroptions.Items.Insert(0, "Entire Project");

ASP.NET FILE:

protected void filteroptions_SelectedIndexChanged(object sender, EventArgs e)
{
    string selected_iteration = filteroptions.SelectedValue;

    Session["iteration"] = selected_iteration;

}

ASCX CONTROL:

protected void Page_Load(object sender, EventArgs e)
{
    proj_name = Request.QueryString["project"].ToString();
    proj_id = Request.QueryString["id"].ToString();

    iteration = (string)Session["iteration"]; 

    BindTagCloud();

}

private void BindTagCloud()
{

    int pro_id = Convert.ToInt32(proj_id);
    int iteration_id = Convert.ToInt32(iteration);

 ....

 if (iteration_id != 0)
    {
        ListView1.DataSource = tagCloudNegativeIteration;
        ListView1.DataBind();

        ListView2.DataSource = tagCloudPositiveIteration;
        ListView2.DataBind();

    }
    else
    {
        ListView1.DataSource = tagCloudNegative;
        ListView1.DataBind();

        ListView2.DataSource = tagCloudPositive;
        ListView2.DataBind();

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铃予 2024-10-23 03:21:07

好吧,您没有存储整数值。此代码:

filteroptions.Items.Insert(0, "Entire Project");

可能没有执行您认为它正在执行的操作。这不是说“添加一个键为 0 且文本为“整个项目”的新列表项。相反,它是说在 位置 0 处插入一个带有值的新列表项和“整个项目”的文本,

您可能需要类似

filteroptions.Items.Insert(0, new ListItem("Entire Project", "0"));

Well, you're not storing an integer value. This code:

filteroptions.Items.Insert(0, "Entire Project");

is probably not doing what you think it is doing. This is not saying "add a new listitem with a key of 0 and the text "Entire Project". Instead, it is saying insert a new listitem at Position 0 with Value and Text of "Entire Project"

you probably want something like,

filteroptions.Items.Insert(0, new ListItem("Entire Project", "0"));

盗梦空间 2024-10-23 03:21:07

问题是您在初始加载时将迭代值设置为 null。如果由于任何原因您的会话变量变为空,您可以使用此代码始终回退到默认值。您可能希望将迭代变量设置为整数,以便可以在负载中对其进行转换。

if(String.IsNullOrEmpty(Sesssion["iteration"])
     iteration = "0";
else
     iteration = Session["iteration"]

并按照阿奎那的建议改变添加项目的方式。

The problem is that you are setting the iteration value to null on the initial load. You can use this code to always fall back to a default if for any reason your session variable becomes null. You might want to make your iteration variable an integer so you can convert it in your load.

if(String.IsNullOrEmpty(Sesssion["iteration"])
     iteration = "0";
else
     iteration = Session["iteration"]

And change the way your adding items to what aquinas suggested.

预谋 2024-10-23 03:21:07

使用这个..

if(Session["iteration"] == Defaultvalue)
  itereation = "0";
else
  iteration = (string)Session["iteration"]; 

默认值是存储在 session["iteration"] 中的值,如果没有存储任何值,则使用 null 作为默认值。

use this..

if(Session["iteration"] == Defaultvalue)
  itereation = "0";
else
  iteration = (string)Session["iteration"]; 

And default value is the value that is stored in session["iteration"] if no value is stored in that then use null as defaultvalue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文