使用动态LINQ捕获Gridview的当前状态

本文关键字:状态 Gridview 捕获 动态 LINQ | 更新日期: 2023-09-27 18:24:41

嗨,提前谢谢。

我想知道是否有人能给我看一个获取Gridview当前状态的例子,以便以后可以使用它来做一些事情。我不确定使用ViewState对象是否是正确的方法,如果是,我需要一个将其保存到ViewState并稍后使用它的示例。

我正在使用asp.net和带有动态LINQ 的c#

使用动态LINQ捕获Gridview的当前状态

您可以使用DataControlRowState从行中获取状态。

来自MSDN:

Member name Description
Alternate:  indicates that the data control row is an alternate row.
The Alternate state can be combined with other states, such as Normal, Edit, or Insert, at any time. These rows might be affected by the AlternateRowStyle property of the data control, if set.
Edit:   indicates that the row is in an edit state, often the result of clicking an edit button for the row. Typically, the Edit and Insert states are mutually exclusive.
Insert: indicates that the row is a new row, often the result of clicking an insert button to add a new row. Typically, the Insert and Edit states are mutually exclusive.
Normal: indicates that the data control row is in a normal state. The Normal state is mutually exclusive with other states except the Alternate state.
Selected:   indicates that the row has been selected by the user.

例如:

protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
  if (rowState & DataControlRowState.Edit) != 0)
  {
     /*Do Stuff that you need here*/
  }
}