I have a dropdown list on my form which should filter out or display my tag cloud for an entire project or for a specific iteration. At the moment, I don't get any errors, but the ASCX control doesn't seem to update. Here is my code, any help would be appreciated!
ASPX FILE:
<asp:DropDownList ID="filteroptions" runat="server" onselectedindexchanged="filteroptions_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
<asp:UpdatePanel ID="UpdateIteration" runat="server">
<ContentTemplate>
<TagCloud:TagCloudControl ID="TagCloudControl1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="filteroptions" />
</Triggers>
</asp:UpdatePanel>
C# FILE:
protected void Page_Load(object sender, EventArgs e)
{
...
filteroptions.DataSource = ds;
filteroptions.DataTextField = "Iteration";
filteroptions.DataValueField = "ProjectIterationID";
filteroptions.DataBind();
filteroptions.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Entire Project", "0"));
}
protected void filteroptions_SelectedIndexChanged(object sender, EventArgs e)
{
string selected_iteration = filteroptions.SelectedValue;
Session["iteration"] = selected_iteration;
}
ASCX CS FILE:
string proj_id, proj_name, iteration;
protected void Page_Load(object sender, EventArgs e)
{
proj_name = Request.QueryString["project"].ToString();
proj_id = Request.QueryString["id"].ToString();
if (String.IsNullOrEmpty((string)Session["iteration"]))
iteration = "0";
else
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();
}
You replaced some code by '...' and therefore this answer might be incorrect.
With the code given I think that the problem is in the Page_Load method of your .aspx file. It appears to be that the binding of the dataset to your dropdownlist happens also on a Postback. When the Page receives it's postback it will bind the dataset to the dropdownlist and set its selectedValue to the first item. When this is done, the event is processed and its listener is called. In your method 'filteroptions_SelectedIndexChanged' you check for the selectedValue and it will have the value of the currently first item and not the value of the Item you selected.
To resolve this put the binding of the dropdownlist in the (!IsPostBack) like this:
If this answer is incorrect because it is based on the wrong assumptions please provide me the complete code and I will think along with you.