我想检查是否选择了gridview
中的行。我怎么能写条件??
if (gridview-row[1].select)
{
//do something
}
else
{
//do something
}
答案 0 :(得分:0)
您可以使用GridViewRow.RowState
属性Asp.net Gridview.RowState
GridViewRow row = yourGridView.SelectedRow; will give the selected row
并像这样检查
if(row.RowState == DataControlRowState.Selected)
{
//selectd
}
答案 1 :(得分:0)
假设您的问题是asp.net,您可以在GridView上设置SelectedIndexChanged事件。只要GridView有新的行选择,就会触发此事件。更多信息here。
<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;
}
答案 2 :(得分:0)
if (GridView.SelectedIndex == rowIndex)
{
// do something
}
else
{
// do something
}
你可以这样写。