我有一个ASP.net GridView(带分页)的网页。 GridView拥有超过10,000行。每行都有一个“ID”字段。将ASP.net GridView的页面设置为包含给定行的页面的有效方法是什么?
这是一个过分简单化,但假设我希望用户能够在文本字段中输入一个仲裁行ID,并将其带到GridView,页面索引自动设置为包含该行的页面的索引与指定的ID。
我曾尝试以下,但它不工作:
DataSet ds = ReportManager.GetDevices(AdHocQuery);
lblRecordCount.Text = String.Format("{0:#,0}", ds.Tables[0].Rows.Count);
string sortDirection = AdHocQuery.SortDirection == "Descending" ? " DESC" : " ASC";
DataView dv = new DataView(ds.Tables[0], string.Empty, AdHocQuery.SortColumnName + " " + sortDirection, DataViewRowState.CurrentRows);
gvAsset.DataSource = dv;
gvAsset.DataBind();
// If there was a device ID passed in the Query String, then change the page to the page that contains the given ID.
if (!string.IsNullOrEmpty(DeviceId))
{
// First, find the row number of the given device Id
int rowNumber = 0;
int i;
for (i = 0; i < dv.Table.Rows.Count; i++)
{
DataRow row = dv.Table.Rows[i];
if (row.Field<Guid>("deviceId").ToString().ToUpper() == DeviceId.ToUpper())
{
rowNumber = i;
break;
}
}
// The page index is going to be the row Number divided by the Page size
// For example, if the page size is 10...
// row 5 is on page 0,
// row 15 is on page 1,
// row 28 is on page 2, and so on
int pageIndex = rowNumber/gvAsset.PageSize;
gvAsset.PageIndex = pageIndex;
此代码编译,但它始终显示在GridView的错误页面。
我该如何编码,以便显示正确的页面?
在我发布的代码片段中,'PageIndex'属性被设置,但它被设置为错误的值。我认为这与分拣有关。 –