嗨,提前感谢。
我想知道是否有人可以向我展示一个获取 Gridview 的当前状态的示例,以便以后可以使用它来做某事。我不确定使用 ViewState 对象是否是正确的方法,如果是这样,我需要一个示例将其保存到 ViewState 并稍后使用它。
我正在使用带有动态 LINQ 的 asp.net 和 c#
您可以使用 . 从行中获取状态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*/
}
}