我有以下控件及其数据绑定。我在这里每页只加载30条记录,但加载30条记录需要4到5秒。
的Xaml:
<telerik:RadGridView
Grid.Row="1"
x:Name="preview"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ItemsSource="{Binding IsAsync=True}"
MaxHeight="1600"
MaxWidth="2560"
/>
的.cs:
private void GetData(int pageIndex)
{
try
{
//get data
MySqlConnection conn = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand("select * from bseg limit " + (pageIndex-1)*30 + ", " + 30, conn);
conn.Open();
var rdr = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(rdr);
**preview.DataContext = dataTable.DefaultView;**
//This line is taking a long time. 3 to 4 seconds.
conn.Close();
//get number of records in table
MySqlCommand cmd1 = new MySqlCommand("select count(*) from bseg;", conn);
conn.Open();
numOfRecords = Convert.ToInt32(cmd1.ExecuteScalar());
numOfPages = numOfRecords / numberOfRecPerPage;
lblTotalPages.Content = " of " + numOfPages.ToString();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
在上面的场景中,我添加了自定义分页,每页只加载30条记录。对于每个下一页,通过使用页面索引,我将加载下30条记录。但我不知道为什么加载数据需要4到5秒。