我在页面添加了一个DropDownList控间,ID为DropDownList1
然后在CS中的PAGE_LOAD中给他赋值,当选择下拉框的时候出发DropDownList1_SelectedIndexChanged的方法,现在的问题是根本在选择下拉框的时候根本没有出发DropDownList1_SelectedIndexChanged的方法,后来我就把PAGLE_LOAD里的赋值代码给去掉了,在ASPX中给DropDownList1赋值,结果就可以触发DropDownList1_SelectedIndexChanged方法,请问这怎么解决,真的很头痛
下面是代码
ASPX:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>CS:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 10; i <= 100; i += 10)
{
ListItem ls = new ListItem();
ls.Text = i.ToString() + "人";
ls.Value = i.ToString();
DropDownList1.Items.Add(ls);
}
DropDownList1.Items.Add(new ListItem("全部", ""));
DropDownList1.SelectedValue = "";
// DropDownList2.Items.Add(new ListItem("--", ""));
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 10; i <= 100; i += 10)
{
ListItem ls = new ListItem();
ls.Text = i.ToString() + "人";
ls.Value = i.ToString();
DropDownList2.Items.Add(ls);
}
DropDownList2.Items.Add(new ListItem("全部", ""));
DropDownList2.SelectedValue = "";
}
然后在CS中的PAGE_LOAD中给他赋值,当选择下拉框的时候出发DropDownList1_SelectedIndexChanged的方法,现在的问题是根本在选择下拉框的时候根本没有出发DropDownList1_SelectedIndexChanged的方法,后来我就把PAGLE_LOAD里的赋值代码给去掉了,在ASPX中给DropDownList1赋值,结果就可以触发DropDownList1_SelectedIndexChanged方法,请问这怎么解决,真的很头痛
下面是代码
ASPX:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>CS:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 10; i <= 100; i += 10)
{
ListItem ls = new ListItem();
ls.Text = i.ToString() + "人";
ls.Value = i.ToString();
DropDownList1.Items.Add(ls);
}
DropDownList1.Items.Add(new ListItem("全部", ""));
DropDownList1.SelectedValue = "";
// DropDownList2.Items.Add(new ListItem("--", ""));
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 10; i <= 100; i += 10)
{
ListItem ls = new ListItem();
ls.Text = i.ToString() + "人";
ls.Value = i.ToString();
DropDownList2.Items.Add(ls);
}
DropDownList2.Items.Add(new ListItem("全部", ""));
DropDownList2.SelectedValue = "";
}
解决方案 »
- 谁帮我解释下这个用用委托异步调用的例子
- 想做个针对博客更新的提醒工具,求点建议~
- ◆C#如何实现字符串对齐◆
- 关于menu的问题
- datagridview 和datatable的问题
- 李红星老师,您好.C#如何实现"取消Shift键的粘键设置"?就是连按Shift键后,就会弹出一个粘键设置的->辅助功能选项,的对话框
- 请问AsyncCallback(IAsyncResult ar)方法执行的代码是在异步线程中执行的还是主线程?
- 请问这个布局怎么弄?关于Winform的Dock?
- 急.怎样实现在调用exe可执行程序呀!
- 怎样用C#实现GB到BIG5的内码转换?
- 请问如何实现
- [**求助**]有关安全问题,就是通不过安全软件~~
2、在DropDownList1_SelectedIndexChanged中添加断点跟踪,我这儿测试没有问题
我去掉了OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
还是不能执行
已经是绑定的
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
这都写进去了呢
去掉了OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
这就没有绑定了,这肯定是不行的
改成 DropDownList1.SelectedIndex = -1;
把 DropDownList1.SelectedValue = "";
改成 DropDownList1.SelectedIndex = -1;
这个只是个默认值而已,改了没有用
而且选择后,下拉框什么东西都没有
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>商户录入</title>
<link href="images/css.css" rel="stylesheet" type="text/css" />
</head><body style="text-align: center">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="10" height="658" valign="top" background="images/test_r2_c3.gif">
</td>
<td valign="top" bgcolor="#FFFFFF">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1%">
<img src="images/middle_1.gif" width="11" height="31"></td>
<td width="98%" background="images/middle_2.gif" class="title">
</td>
<td width="1%">
<img src="images/middle_3.gif" width="11" height="31"></td>
</tr>
<tr>
<td colspan="3">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BAD0EC">
<tr>
<td height="625" valign="top" bgcolor="#FFFFFF">
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<form id="frmPost" method="post" runat="server">
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="1" class="mytable">
<tbody>
<tr>
<td align="right" bgcolor="#ffffff">
公司全称:</td>
<td height="20" align="left" bgcolor="#ffffff">
<asp:DropDownList ID="DropDownList1" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" runat="server">
<%--<asp:ListItem Value ="1">1</asp:ListItem>
<asp:ListItem Value ="2">2</asp:ListItem>
<asp:ListItem Value ="3">3</asp:ListItem>
<asp:ListItem Value ="4">4</asp:ListItem>--%>
</asp:DropDownList></td>
<td align="right" bgcolor="#ffffff">
公司全称:</td>
<td height="20" align="left" bgcolor="#ffffff">
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
</asp:DropDownList></td>
</tr>
</tbody>
</table>
<br />
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="7" valign="top" background="images/test_r3_c5.gif" bgcolor="#EEF3FA">
</td>
</tr>
<tr>
<td width="10">
<img name="test_r5_c3" src="images/test_r5_c3.gif" width="10" height="25" border="0"
id="test_r5_c3" alt="" /></td>
<td background="images/test_r5_c4.gif">
</td>
<td>
<img name="test_r5_c5" src="images/test_r5_c5.gif" width="7" height="25" border="0"
id="test_r5_c5" alt="" /></td>
</tr>
</table>
</body>
</html>
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using LongSun.Platform.Helper;
using LongSun.Platform.Util.Page;
using LongSun.Platform.Util.FacePage;
using LongSun.Platform.Tool.Web;public partial class BusiAccount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 10; i <= 100; i += 10)
{
DropDownList1.Items.Add(new ListItem(i.ToString()));
}
DropDownList1.Items.Add(new ListItem("全部", ""));
DropDownList1.SelectedValue = "";
DropDownList2.Items.Add(new ListItem("--", ""));
}
}
//protected void Insert(object sender, EventArgs e)
//{
//}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("aaaaaaaaaa");
for (int i = 10; i <= 100; i += 10)
{
ListItem ls = new ListItem();
ls.Text = i.ToString() + "人";
ls.Value = i.ToString();
DropDownList2.Items.Add(ls);
}
DropDownList2.Items.Add(new ListItem("全部", ""));
DropDownList2.SelectedValue = "";
}
//protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
//{ //}
}
{}
在这个方法里面初始发就可以了
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion把上面这段加到你的代码里去。
我这边完全可以。