gpt4 book ai didi

c# - GridView分页问题

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:08 25 4
gpt4 key购买 nike

我有一个设置为进行分页的 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();
}

最佳答案

我认为根据您的aspx 和您的.cs。您的 css 文件“GridView1”中存在一些问题。尝试删除 css 类并告诉我们。问题是否仍然存在。

注意:

这与您的问题无关。但我认为你应该将你的代码分层而不是将所有代码都写在你的页面代码后面。

阅读:

  • 在 asp.net 中分层。
  • ORM。

关于c# - GridView分页问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com