Gridview中选择的行+ 1?

时间:2014-03-29 17:08:30

标签: c# asp.net gridview row selected

有没有办法在c#(gridview)中选择所选行的下一行?

例如,如果我选择第二行,它将选择第三行

protected void ProjectsTBL_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = ProjectsTBL.SelectedRow;
    Session["selectedrow"] = row;
    Response.Redirect("ProjectDetails.aspx");
}

在Asp.net

3 个答案:

答案 0 :(得分:1)

试试这个示例代码:

protected void ProjectsTBL_SelectedIndexChanged(object sender, EventArgs e)
{
    // Get index of the currently selected row:
    int rowIndex = ProjectsTBL.SelectedIndex;

    // Verify the row exists and it's not the last row:
    if (rowIndex < 0 || rowIndex >= ProjectsTBL.Rows.Count - 1)
        return;

    // Get the next row:
    Session["selectedrow"] = ProjectsTBL.Rows[rowIndex + 1];
    Response.Redirect("ProjectDetails.aspx");
}

答案 1 :(得分:0)

protected void ProjectsTBL_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = ProjectsTBL.SelectedRow;
    if (row.RowIndex >= ProjectsTBL.Rows.Count - 1) { return; }

    GridViewRow selectedRow = ProjectsTBL.Rows[row.RowIndex + 1];

    row.RowState = DataControlRowState.Normal;
    selectedRow.RowState = DataControlRowState.Selected;

    Session["selectedrow"] = selectedRow;
    Response.Redirect("ProjectDetails.aspx");
}

答案 2 :(得分:-1)

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex != -1)
    {
          int selIndex = e.RowIndex;
          int newSelIndex = selIndex + 1;
          DataGridView1.CurrentCell = DataGridView1.Rows[newSelIndex].Cells[0];
    }
}

试试这个我希望这个帮助