Questions tagged «behavior»

11
DropDownList中的ListItems属性在回发时丢失了吗?
一位同事向我展示了这一点: 他在网页上有一个DropDownList和一个按钮。这是背后的代码: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ListItem item = new ListItem("1"); item.Attributes.Add("title", "A"); ListItem item2 = new ListItem("2"); item2.Attributes.Add("title", "B"); DropDownList1.Items.AddRange(new[] {item, item2}); string s = DropDownList1.Items[0].Attributes["title"]; } } protected void Button1_Click(object sender, EventArgs e) { DropDownList1.Visible = !DropDownList1.Visible; } 在页面加载时,将显示项目的工具提示,但在第一次回发时,属性将丢失。为什么会这样,并且有任何解决方法?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.