How to get values from the selected row in the gridview by clicking on the button

0

I need to make sure that when selecting a line and clicking the Approve button, the button takes all the values of the line and plays in a variable and then delete the line

ThisisthecodeformyGridView

<asp:GridViewID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID_PTD" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." PageSize="3">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="CAMINHO" HeaderText="CAMINHO" SortExpression="CAMINHO" />
            <asp:BoundField DataField="NOME" HeaderText="NOME" SortExpression="NOME" />
            <asp:BoundField DataField="PROFESSOR" HeaderText="PROFESSOR" SortExpression="PROFESSOR" />
            <asp:BoundField DataField="ETEC" HeaderText="ETEC" SortExpression="ETEC" />
            <asp:BoundField DataField="DATA" HeaderText="DATA" SortExpression="DATA" />
            <asp:TemplateField HeaderText="Documentos">
            <EditItemTemplate>
                        <a ID="hpCaminho" target="_blank" class="materialize-textarea"  href ='<%# Bind("CAMINHO") %>' runat="server">Abrir</a>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <a ID="hpCaminho" target="_blank" class="materialize-textarea"  href ='<%# Bind("CAMINHO") %>' runat="server">Abrir</a>
                    </ItemTemplate>  
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
asked by anonymous 10.01.2018 / 18:32

1 answer

0

I have not been able to deal with this for some time, but the way is here:

<asp:GridView ID="GridView1" runat="server"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged"  ...

And no behind:

  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  {
    var grid = GridView1 as GridView;
    var i = GridView1.SelectedIndex;
    //Não lembro, mas acho que a coluna do "Selecionar" conta então comecei com 1    
    string Caminho = grid.Rows[i].Cells[1].Text;
    string Nome = grid.Rows[i].Cells[2].Text;
    string Professor = grid.Rows[i].Cells[3].Text;
    string Etec = grid.Rows[i].Cells[4].Text;
    string Data = grid.Rows[i].Cells[5].Text;

    GridView1.DeleteRow(i);
  }
    
11.01.2018 / 19:33