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

Asked

Viewed 2,819 times

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

inserir a descrição da imagem aqui

this and the code of my Gridview

        <asp:GridView ID="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>

1 answer

0


It’s been a long time since I’ve handled this, but the way is this way:

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

And in the 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);
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.