我有一个从
背后的代码填充的asp列表框 <asp:ListBox ID="UploadsApprovedCountries" EnableViewState="true" runat="server" Rows="1" AutoPostBack="True" OnSelectedIndexChanged="SelectedCountryChange"></asp:ListBox>
protected void Load_Countries()
{
ListItem ps = new ListItem("Please select", "");
ps.Value = "";
UploadsApprovedCountries.Items.Add(ps);
foreach (string cntry in Countries.CountriesArray())
{
UploadsApprovedCountries.Items.Add(new ListItem(cntry, cntry));
}
}
在我的Page_Load中,我称之为
if (!IsPostBack)
{
Load_Countries();
}
并在autopostback上调用此方法
protected void SelectedCountryChange(object sender, EventArgs e)
{
filter = UploadsApprovedCountries.SelectedItem.Value;
Response.Write("line 589");
}
然而,我似乎没有做过任何实际调用此方法的事情。从不填充过滤器字符串和&#34;行589&#34;永远不会被写出来。
任何人都可以帮忙吗
整个我的asp.net页面
asp:Content ContentPlaceHolderID="ContentMainBody" ID="LocalMainBody" runat="server">
<h1> administration</h1>
<div class="clearboth"></div>
<div>
<div class="demo">
<div id="tabs">
<ul>
<li><a href="#tabs-1">Uploads awaiting approval</a></li>
<li><a href="#tabs-3">Uploads approved</a></li>
<li><a href="#tabs-2">Sign-ups awaiting approval</a></li>
<li><a href="#tabs-4">Sign-ups approved</a></li>
<li><a href="#tabs-5">Rejected</a></li>
</ul>
<div id="tabs-5">
<h2>Rejected submissions</h2>
<div id="rejectedSubmissions" runat="server">
</div>
</div>
<div id="tabs-1">
<h2>Uploads awaiting approval</h2>
<div id="matUnautherised" runat="server">
</div>
<div class="clearboth"></div>
</div>
<div id="tabs-3">
<h2>Uploads live on site</h2>
<asp:ListBox ID="UploadsApprovedCountries" EnableViewState="true" runat="server" Rows="1" AutoPostBack="True" OnSelectedIndexChanged="SelectedCountryChange" OnTextChanged="SelectedCountryChange"></asp:ListBox>
<div id="matAutherised" runat="server">
</div>
<div class="clearboth"></div>
</div>
<div id="tabs-2">
<h2>Sign-ups awaiting approval</h2>
<div id="signups" runat="server">
</div>
<div class="clearboth"></div>
</div>
<div id="tabs-4">
<h2>Sign-ups live on site</h2>
<div id="signupsapproved" runat="server">
</div>
</div>
</div>
</div>
</div>
我刚刚注意到,如果我将列表框中的代码更改为此
<asp:ListBox ID="UploadsApprovedCountries" EnableViewState="true" runat="server" Rows="1" AutoPostBack="True" OnSelectedIndexChanged="SelectedCountryChange">
<asp:ListItem Value="test1" Text="test1"></asp:ListItem>
<asp:ListItem Value="test2" Text="test2"></asp:ListItem>
<asp:ListItem Value="test3" Text="test3"></asp:ListItem>
<asp:ListItem Value="test4" Text="test4"></asp:ListItem>
<asp:ListItem Value="test5" Text="test5"></asp:ListItem>
</asp:ListBox>
并且不要从数据源填充它然后它按预期工作。添加后面的代码中的项目和直接添加它们之间有区别吗?
答案 0 :(得分:0)
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Load_Countries();
UploadsApprovedCountries.EnableViewState = true;
}