我正在为sharepoint 2010开发一个Web部件。我有一个事件的下拉列表。在更改时,它应显示一个或另一个标签,具体取决于值,但这不起作用。我确实把autopostback设置为true但我不希望每次点击下拉列表时都会加载整个页面。
protected override void CreateChildControls()
{
toolPartPanel = new Panel();
ddl = new DropDownList();
ddl.ID = "ddl";
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
ddl.EnableViewState = true;
ddl.Items.Add("a");
ddl.Items.Add("b");
label1 = new Label();
label1.Text = "a selected";
label1.Visible = false;
label2 = new Label();
label2.Text = "b selected";
label2.Visible = false;
this.Controls.Add(label1); this.Controls.Add(label2);
this.Controls.Add(ddl);
this.Controls.Add(toolPartPanel);
base.CreateChildControls();
}
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
Selected = ddl.SelectedValue.ToString();
if (Selected == "a")
{
label1.Visible = true;
}
else
{
if (Selected == "b")
{
label2.Visible = true;
}
}
}
答案 0 :(得分:1)