ArrayList al = new ArrayList();
写到外面去 你这么定义是局部的
ArrayList al = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
写到外面去 你这么定义是局部的
ArrayList al = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
解决方案 »
- linkbutton无法触发oncommond事件
- 获取不了前台控件修改后的值..
- 在asp.net页面插入图能做出GIS的效果么?
- 传值的问题
- DropDownList 的 SelectIndexChanged事件问题。
- Page_PreInit()是哪里来的?为什么会执行?
- 一个关于数据同步的问题
- 在datagrid的模板中添加button 为什么不触发_ItemCommand()事件呢?? 奇怪啊 急!!
- 用C#开发ASP.NET,请问如何实现UBB代码最有效率.见内.
- EF源码项目的UnitTests项目怎么使用
- 关于数据库更新的超级难题,来挑战
- 遍历页面Dropdownlist控件的问题
Panel panel1 = (Panel)Page.FindControl("panel1");
for (int i = 0; i < panel1.Controls.Count; i++)
{
if (panel1.Controls[i] is DropDownList)
{
DropDownList c1 = (DropDownList)panel1.Controls[i];
if(c1.SelectedValue!="请选择")
{
Label ls = (Label)al[i];
strSql.Append(" and "+ls.Text+'='+c1.SelectedValue);
Response.Write(strSql); }
}
}
{
if(i < al.Length)
{
Label ls = (Label)al[i];
strSql.Append(" and "+ls.Text+'='+c1.SelectedValue);
Response.Write(strSql);
}
}
ViewState["al"] = al; //储存arraylist
用的时候
ArrayList al = (ArrayList)ViewState["al"];或者
Session["al"] = al;ArrayList al = (ArrayList)Session["al"];
(下面的运行时当我点滴七个dropdownlist时,al[i]会溢出)
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList al = (ArrayList)ViewState["al"];
//Response.Write(al[1]); Panel panel1 = (Panel)Page.FindControl("panel1");
for (int i = 0; i < panel1.Controls.Count; i++)
{
if (panel1.Controls[i] is DropDownList)
{
DropDownList c1 = (DropDownList)panel1.Controls[i];
if (c1.SelectedValue != "请选择")
{
strSql.Append(" and " + al[i] + '=' + c1.SelectedValue);
} }
}
}
已找到,但现在我在button中要引用时说我:索引超出范围。必须为非负值并小于集合大小。
Panel panel1 = (Panel)Page.FindControl( "panel1 ");
for (int i = 0; i < panel1.Controls.Count; i++)
{
if (panel1.Controls[i] is DropDownList)
{
DropDownList c1 = (DropDownList)panel1.Controls[i];
if(c1.SelectedValue!= "请选择 ")
{
Label ls = (Label)al[i];
strSql.Append( " and "+ls.Text+ '= '+c1.SelectedValue);
Response.Write(strSql);
}
}
}
============================================================================1.AreEqual(panel1.Controls.Count,al.Length)?
2.al[panel1.Controls.Count-1]可以访问吗?