【发布时间】:2011-10-22 05:31:04
【问题描述】:
我有一个设置为进行分页的gridview,但它不能正常工作。
只有第一个页面的控件是可见的 - 其他页面呈现了框,但其中没有控件。
有人知道为什么会这样吗?我检查过我有超过一页的数据。
谢谢,
奥利弗
我附上了一张截图,希望能说明我的问题。
http://i.stack.imgur.com/NOFnB.jpg
编辑:gridview 的来源
<asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="GridView1_PageIndexChanging"
CssClass="GridView1" OnSelectedIndexChanged="GridView_SelectedIndexChanged"
AllowPaging="True" PageSize="20">
<selectedrowstyle backcolor="LightCyan" forecolor="DarkBlue" font-bold="true" />
</asp:GridView>
使用 c# 生成的数据集填充它
编辑:c# 代码隐藏
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
public void bindGridView()
{
//declare the connection string to use
string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
//create sql connection
SqlConnection mySQLconnection = new SqlConnection(connectionString);
//open connection
mySQLconnection.Open();
//define command using text string
SqlCommand mySqlCommand = new SqlCommand(sqlTester, mySQLconnection);
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlCommand);
//create dataset to fill gridview with
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
//fill gridview
GridView1.DataSource = myDataSet;
GridView1.DataBind();
//close the sql connection
mySQLconnection.Close();
}
【问题讨论】:
-
您能否展示一下用于将数据集绑定到gridview 的代码?
-
哦,您是否有机会处理 PageIndexChanged 事件?
-
你检查过源代码吗?数字也没有出现在那里吗?我想知道它是否是未选择页码的 CSS 问题。
-
你去 - 我的数据集是使用字符串 sqlTester 创建的,我有一些希望处理 pageindexchange 事件的代码 - 我应该处理 pageindexchanged 事件吗?
-
@curt 我看过了,它似乎正在生成 - 有 10 行,每行都有一个 href 链接
标签: c# asp.net gridview paging