DropDownList OnSelectedIndexChanged 报错
错误: 无法跳转,原因:
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=");
}
}
高手看看。小弟感谢。