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();
}
}
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.
And change the way your adding items to what aquinas suggested.