Pass Aspx page values to Aspx.cs

1

I have an Aspx page the following code that loads a list of items. It is working, the list is displayed normally.

<table width="100%" class="table table-striped">
<tr>
<th>Id</th>
<th>Nome</th>
<th>CPF</th>
<th>E-mail</th>
<th>Adicionar Telefone</th>
<th>Editar | Deletar</th>
</tr>
<% foreach (var item in pessoaList) { %>
<tr>
<td><%= item.id %></td>
<td><%= item.nome %></td>
<td><%= item.cpf %></td>
<td><%= item.email %></td>
<td><!-- Código Modal --></td>

<td>
<asp:Button ID="EditarPessoaButton" cssClass="btn btn-info" runat="server" CommandName="EditarPessoa" Text="Editar" ValidationGroup="EditarPessoa" onclick="EditarPessoaButton_Click"/>
<asp:Button ID="ExcluirPessoaButton" cssClass="btn btn-danger" runat="server" CommandName="ExcluirPessoa" Text="Excluir" ValidationGroup="ExcluirPessoa" onclick="ExcluirPessoaButton_Click"/>
</td>
</tr>
<% } %>
</table>

I want to pass the value of <%= item.id %> per row to table row as a parameter to delete and edit data. I tried using the asp Textbox component to save the values but to no avail. I need the <%= item.id %> value in aspx.cs. How to pass the value line by line from <%= item.id %> to layer aspx.cs?

[Edit] Note: I would like to pass all item values between the Taglibs to text format in order to manipulate them. Asp Component Textbox says that it is not supported when added between the <td></td> tags and also generates run-time error.

[Edit2] Follow resolution with GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"     Width="100%" OnRowCommand="GV_RowCommand" AllowSorting="True"     DataSourceID="SqlDataSource1" AllowPaging="True" DataKeyNames="id" class="table     table-striped" style="border-color:transparent; color:black;">
<Columns>
<asp:BoundField ReadOnly="True" HeaderText="ID" DataField="id"     SortExpression="id" Visible="false"></asp:BoundField>

<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:TextBox Text=<%# Eval("id")%> ID="txtIdPessoa" runat="server"     visible="false"/>
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField HeaderText="NOME" DataField="nome"
SortExpression="nome"></asp:BoundField>

<asp:BoundField HeaderText="CPF" DataField="cpf"
SortExpression="cpf"></asp:BoundField>

<asp:BoundField HeaderText="E-MAIL" DataField="email"
SortExpression="email"></asp:BoundField>

<asp:TemplateField HeaderText="TELEFONE">
<ItemTemplate>
<!-- Codigo Modal -->
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="EDITAR | EXCLUIR">
<ItemTemplate>
<asp:Button Text="Editar" cssClass="btn btn-info" ID="btnUpdPessoa"     runat="server" CausesValidation="false" CommandName="EditarPessoaButton_Click"     CommandArgument='<%# Eval("id")%>' />                               
<asp:Button Text="Excluir" cssClass="btn btn-danger" ID="btnDelPessoa"     runat="server" CausesValidation="false" CommandName="ExcluirPessoaButton_Click"     CommandArgument='<%# Eval("id")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ItauDAL %>"
SelectCommand="select * from Pessoa"
UpdateCommand="UPDATE [Pessoa] SET [nome] = @nome , [cpf] =  @cpf , [email]     = @email 
WHERE [id] = @id" >
<UpdateParameters>
<asp:Parameter Type="String" Name="nome"></asp:Parameter>
<asp:Parameter Type="String" Name="cpf"></asp:Parameter>
<asp:Parameter Type="String" Name="email"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
    
asked by anonymous 23.12.2017 / 21:38

1 answer

1

As you are working with webforms, it would be best to use a component such as GridView, which already has events that facilitate this work.

Furthermore, if you prefer to keep the current structure, the only way I know of passing data from an .aspx page to its respective code-behind is through the HiddenField component.

    
24.12.2017 / 15:32