我使用asp.net gridview与分页/排序完美的工作。我在网格外面有一个按钮,说“批准当前页面”,它只获取当前页面中的行并发送到db进行处理。
BindGridView(){
//this will set the initial
var firstPage = _clientList.Take(xgvClientApprovals.PageSize).ToList();
}
OnApproveClicked(){
//this will get rows count in each paginated page but I am unable to get
//the data itself.
var currentPageRows = xgvClientApprovals.Rows;
//Here I would like to get only the current page rows.
}
您可以在GridView中使用DataKeyNames
来始终获取正确的数据。
<asp:GridView ID="GridView1" runat="server" DataKeyNames="approvalID">
然后只需从行中读取正确的DataKey
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
int approvalID = Convert.ToInt32(GridView1.DataKeys[i].Values[0]);
}
}