关于DropDownList1_SelectedIndexChanged一个难以理解的问题。。。。
以下是代码:问题是不执行DropDownList1_SelectedIndexChanged方法。。请大家帮帮看看为什么???
<%@ Register TagPrefix="eshop" TagName=HeaderMenu Src="UserControl/HeaderMenu.ascx" %>
<%@ Register TagPrefix="eshop" TagName=CategoryList Src="UserControl/CategoryList.ascx" %>
<%@ Page language="c#" Codebehind="Productlist.aspx.cs" AutoEventWireup="false" Inherits="eshop_test.Productlist" enableViewState="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Productlist</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE height="120" cellSpacing="0" cellPadding="0" width="512" border="0" runat="server">
<TR bgColor="lightsteelblue">
<TD style="WIDTH: 633px; HEIGHT: 25px" colSpan="2" height="25"><eshop:headermenu id="Header" runat="server"></eshop:headermenu></TD>
</TR>
<TR vAlign="top">
<TD width="25%" height="10"><eshop:categorylist id="Category" runat="server"></eshop:categorylist></TD>
<TD style="WIDTH: 555px" height="10">
<h3>查询结果:</h3>
<asp:datagrid id="DataGridSearch" runat="server" AutoGenerateColumns="False" Width="528px">
<HeaderStyle BackColor="DeepSkyBlue"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="ProductId" HeaderText="商品编号"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="商品名称">
<ItemTemplate>
<asp:HyperLink ID=shangbin Runat=server text='<%# DataBinder.Eval(Container.DataItem,"ProductName")%>' NavigateUrl='<%# "Productlist.aspx?productID="+ DataBinder.Eval(Container.DataItem,"ProductId")%> '>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Intro" HeaderText="商品简单描述"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="购买">
<ItemTemplate>
<asp:HyperLink ID="Hyperlink2" Runat=server NavigateUrl='<%# "AddToCart.aspx?productID="+ DataBinder.Eval(Container.DataItem,"ProductId")%> '>
<img src="Images\next_down.gif">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<table width="100%" runat="server">
<tr>
<td style="WIDTH: 361px">总共<asp:label id="PageCount" Runat="server"></asp:label>样商品
共有
<asp:label id="Label1" runat="server" Width="32px">Label</asp:label>页</td>
<td align="right">转到了第
<asp:dropdownlist id="DropDownList1" runat="server" AutoPostBack="True" ></asp:dropdownlist>页</td>
</tr>
</table>
</TD>
</TR>
</TD></TR></TABLE>
</FONT>
</form>
</body>
</HTML>
这以下是脚体:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace eshop_test
{
/// <summary>
/// Productlist 的摘要说明。
/// </summary>
public class Productlist : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink shangbin;
protected System.Web.UI.WebControls.HyperLink Hyperlink2;
protected System.Web.UI.WebControls.DataGrid DataGridSearch;
protected System.Web.UI.WebControls.Label PageCount;
protected System.Web.UI.WebControls.DataGrid ProductDataGrid1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
private static int PageSize=5;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//如果是第一次加载,则加载第一页。
if(!Page.IsPostBack)
{
ShowPage(1,PageSize);
//得到商品的总数。。。
PageCount.Text=eshop_test.BLL.Product.GetProductCountByCategory(int.Parse(Request.Params["categoryID"])).ToString();
}
}
public void ShowPage( int PageIndex,int pageSize)
{
//加载选定项目的所有商品。
// ProductDataGrid1.DataSource=eshop_test.BLL.Product.GetProductsByCategory(int.Parse(Request.Params["categoryID"]), PageIndex, pageSize);
// ProductDataGrid1.DataBind();
string connstring="server=fang;database=eshop_test;uid=sa;pwd=2200437";
SqlConnection objcon=new SqlConnection(connstring);
objcon.Open();
SqlCommand objcom=new SqlCommand();
objcom.Connection=objcon;
objcom.CommandType=CommandType.StoredProcedure ;
objcom.CommandText="GetProductByCategory";
objcom.Parameters.Add("@categoryId",int.Parse(Request.Params["categoryID"]));
objcom.Parameters.Add("@pageSize",pageSize);
objcom.Parameters.Add("@pageIndex",PageIndex);
DataGridSearch.DataSource=objcom.ExecuteReader();
DataGridSearch.DataBind();
objcon.Close();
//得到商品的总页数后绑定到 DropDownList1控件。。。
int tatolcount=eshop_test.BLL.Product.GetProductCountByCategory(int.Parse(Request.Params["categoryID"]));
int count;
if(tatolcount%PageSize==0)
{
count=tatolcount/PageSize;
Label1.Text=count.ToString();
}
else
{
count=tatolcount/PageSize+1;
Label1.Text=count.ToString();
}
formfell.Items.Clear();
for(int i=1;i<=count;i++)
{
ListItem page1=new ListItem(i.ToString());
DropDownList1.Items.Add(page1);
}
DropDownList1.SelectedItem.Text=PageIndex.ToString();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
int selectV= Convert.ToInt32(DropDownList1.SelectedItem.Text );
ShowPage(selectV,PageSize);
}
}
}