我写的DataGrid分页 却分不了页
yok77 2007-03-22 02:13:10 我把代码拷给大家,大家看看哪里不对?
public partial class newslist : System.Web.UI.UserControl
{
private string newTypeID;
public string NewTypeID
{
set
{
this.newTypeID = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
SqlConnection con = DB.createCon();
SqlCommand cmd = new SqlCommand("select newsTypeName from newsType where newsTypeID='" + this.newTypeID + "'", con);
con.Open();
string newTypeName = Convert.ToString(cmd.ExecuteScalar());
this.Label1.Text = newTypeName;
cmd.CommandText = "select * from newsMaster where newsTypeID='" + this.newTypeID + "'";
this.DataGrid1.DataSource = cmd.ExecuteReader();
this.DataGrid1.DataBind();
}
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.DataGrid1.DataBind();
}
}