我想检查是否gridview
选择了 a 中的一行。如果条件我怎么写?
if (gridview-row[1].select)
{
//do something
}
else
{
//do something
}
假设您的问题是 asp.net,您可以在 GridView 上设置 SelectedIndexChanged 事件。只要 GridView 有新的行选择,就会触发此事件。更多信息在这里。
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="False"
autogenerateselectbutton="True"
allowpaging="True"
selectedindex="1"
onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
runat="server" DataKeyNames="CustomerID"> ...
事件监听器,您可以在其中获取所选行
void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
{
// Gets the currently selected row based on the selected index changed event
//
var selectedRow = CustomersGridView.SelectedRow;
}
你可以使用GridViewRow.RowState
属性Asp.net Gridview.RowState
GridViewRow row = yourGridView.SelectedRow; will give the selected row
像这样检查
if(row.RowState == DataControlRowState.Selected)
{
//selectd
}
if (GridView.SelectedIndex == rowIndex)
{
// do something
}
else
{
// do something
}
你可以这样写。