DropDownList OnSelectedIndexChanged 报错

wendaocy 2008-10-03 03:57:24
错误: 无法跳转,原因:
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit(); //////对象不支持此属性或方法。
}
}
前台部分:
跳转到:<asp:DropDownList ID="change" AutoPostBack="true" OnSelectedIndexChanged="ChangeLink" runat="server" Height="18" style="font-size: 12px; color: gray">
</asp:DropDownList>
后台部分:


public partial class New_Show : System.Web.UI.Page
{
public string connection = System.Configuration.ConfigurationSettings.AppSettings["DZW2008ConnectionString2"];
public string menu,id;
PagedDataSource MyPaged = new PagedDataSource();
DataSet News = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{



if (Request["Class_Id"].Trim().Length > 0)
{
id = Request["Class_Id"].Trim();
}
if (Request["Class_Name"].Trim().Length > 0)
{
id = GetNewClass(Request["Class_Name"].Trim());
}
string sql = "select Dz_News.*,Dz_Menu.Menu_Name from Dz_News,Dz_Menu where Dz_Menu.Menu_Id = Dz_News.New_Type and Dz_Menu.Menu_Id ='" + id + "' and Dz_News.IsDel ='0' order by Dz_news.add_time Desc";

SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
// Adapter.Fill(News);

////////////////////////////////////
try
{
//填充数据集\
adapter.Fill(News);
// MyAdapter.Fill(MySet);
//创建分页类

//设置数据源
MyPaged.DataSource = News.Tables[0].DefaultView;

//允许分页
MyPaged.AllowPaging = true;
//设置每页显示的项数
MyPaged.PageSize = 5;
//定义变量用来保存当前页索引
int MyCurrentPage;
//判断是否具有页面跳转的请求
if (Request.QueryString["Page"] != null)
MyCurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
else
MyCurrentPage = 1;
//设置当前页的索引
MyPaged.CurrentPageIndex = MyCurrentPage - 1;
//显示状态信息
this.Label1.Text = "共有新闻<font color='red'>" + News.Tables[0].Rows.Count.ToString() + "</font>条  当前页:<font color='red'>" + MyCurrentPage.ToString() + "/</font>" + MyPaged.PageCount;
// this.Label3.Text = "共有各类信息<font color='red'>" + MySet.Tables[0].Rows.Count.ToString() + "</font>条  当前页:<font color='red'>" + MyCurrentPage.ToString() + "/</font>" + MyPaged.PageCount;
//如果当前页面不是首页
if (MyPaged.IsFirstPage)
{
this.HperLink3.Visible = false;

}
if (!MyPaged.IsFirstPage)
{
this.HperLink3.Visible = true;
this.HperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1"+"&Class_Id=" + id+"&Class_Name=";
//设置"上一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
this.HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage - 1 + "&Class_Id=" + id+"&Class_Name=");
// this.HyperLink3.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage - 1);
}
//如果当前页面不是最后一页
if (!MyPaged.IsLastPage)
{
//设置"下一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
this.HyperLink4.Visible = true;
this.HyperLink4.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + MyPaged.PageCount + "&Class_Id=" + id + "&Class_Name=";
this.HyperLink2.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage + 1 + "&Class_Id=" +id +"&Class_Name=");

// this.HyperLink4.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(MyCurrentPage + 1);
}
//进行数据绑定
this.new_list.DataSource = MyPaged;
this.new_list.DataBind();
this.change.Items.Clear();
for (int i = 1; i <= MyPaged.PageCount; i++)
{
//this.change.Items.Clear();
ListItem list = new ListItem();
list.Value = i.ToString();
list.Text = "第" + i + "页";
this.change.Items.Add(list);
// this.change.DataValueField = i.ToString();

}

}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
News.Dispose();
}
menu = News.Tables[0].Rows[0]["Menu_Name"].ToString();
}


}


public string GetNewClass(string id)
{

////未写出。
}



protected void ChangeLink(object sender, EventArgs e)
{
this.change.AutoPostBack = true;
Response.Write(Request.CurrentExecutionFilePath + "?Page=" + change.SelectedItem.Value.ToString() + "&Class_Id=" + id + "&Class_Name=");
}
}

高手看看。小弟感谢。

...全文
456 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cloudgamer 2008-10-04
  • 打赏
  • 举报
回复
不清楚
帮顶
zlb789 2008-10-04
  • 打赏
  • 举报
回复
不清楚
帮你顶


自己调式看能发现错误的地方不
leecopper 2008-10-04
  • 打赏
  • 举报
回复
进来,帮顶一下
mystudy2000 2008-10-04
  • 打赏
  • 举报
回复
我猜测可能是你页面上某个控件的ID名字有问题。
在aspx文件里的所有标签的ID命名是有限制的,简单例子:像submit,function之类的javascript的关键词是不能用的。同样DOM里的关键词也是不能用的。我之前就是因为用了submit做ID而出现了和你现在一样的错误提示。
你可以用html注释把你页面上的标签一个个注释掉,每注释一个就测一下,这样就知道是哪个标签的ID有问题了。
如果页面上的标签太多,无法这样测,那就把所有的ID名字改成xx_xx这样有前缀加下划线的,就不会有问题了。
希望对你有帮助。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧