请教gridview中使用ddl重新绑定数据的问题
我用gridview想实现以下功能。
默认显示的是所有的数据。。。
然后在页面有个dropdownlist(不在gridview中),当我选择后 显示该大类的所有数据。
那么我在dropdownlist的事件中重新为ID为database的DataSource 指定了selectcommand语句,然后为gridview重新绑定了database..
现在的问题是。。。
点击DDL的大类后显示第一页正常。。点击下一页就错。。比如一共两页。。第一页正常。。第二页不但没有数据。分页显示的也错了 成了 2/1(应该是2/2)
代码如下:
<asp:GridView ID= "gridview_article " runat= "server " AutoGenerateColumns= "False " DataSourceID= "database "
EmptyDataText= "无记录 " GridLines= "None " CssClass= "cTable table tCenter " AllowPaging= "true " PageSize= "16 " OnDataBound= "gridview_article_databound ">
</gridview>
<asp:SqlDataSource ID= "database " runat= "server " ConnectionString= " <%$ ConnectionStrings:databaseConnectionString %> "
ProviderName= " <%$ ConnectionStrings:databaseConnectionString.ProviderName %> ">
<SelectParameters>
<asp:ControlParameter ControlID= "Big_Column " PropertyName= "SelectedItem.Value " Name= "FirstColumnNum " />
<asp:ControlParameter ControlID= "Son_Column " PropertyName= "SelectedItem.Value " Name= "SecondColumnNum " />
</SelectParameters>
</asp:SqlDataSource>
cs页面
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//指定database默认的selectcommand语句
database.SelectCommand = "SELECT [num],LEFT(Title,15) as Title, [FirstColumnNum],[FirstColumnName],[Times], [IssueDate] FROM [Article] ";
}
Button_First.CommandName= "1 ";
Button_Next.CommandName=(gridview_article.PageCount==1 ? gridview_article.PageCount.ToString() : Convert.ToString((gridview_article.PageIndex+2)));
Button_Pre.CommandName=(gridview_article.PageIndex==0 ? "1 " : gridview_article.PageIndex.ToString());
Button_Last.CommandName=gridview_article.PageCount.ToString();
}
//分页LinkButton
protected void PagerButtonClick(object sender,EventArgs e)
{
gridview_article.PageIndex=Convert.ToInt32(((Link