1

我想检查是否gridview选择了 a 中的一行。如果条件我怎么写?

if (gridview-row[1].select)

{
    //do something
}

else

{
   //do something
}
4

3 回答 3

0

假设您的问题是 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;
  }
于 2013-05-09T04:48:42.260 回答
0

你可以使用GridViewRow.RowState属性Asp.net Gridview.RowState

GridViewRow row = yourGridView.SelectedRow; will give the selected row 

像这样检查

 

if(row.RowState == DataControlRowState.Selected)
    {
      //selectd
    } 
于 2013-05-09T04:41:02.450 回答
0
if (GridView.SelectedIndex == rowIndex)
{
    // do something
}
else
{
    // do something
}

你可以这样写。

于 2013-05-09T05:33:37.363 回答