0
Good evening, my question is this... I want to make a "select" of the data of a line of the Repeater control according to the clicked Linkbutton (the white pencil of blue background), thus storing this data in different Sessions (name, user, sector, position, shift and extension), so to throw this data in a form (which is on another page, redirected after pressing Linkbutton) so that the form Textboxes receive these Sessions in String format so that they can be edited. That’s my goal, but what’s stopping me from going on is just getting the data from the button line clicked. Follow images for better understanding.
This is the result of the page, now for example, if I click on the Edit button (pencil) of Zeca Amaral I wanted to get the Session["name"] = "Zeca Amaral", Session["user"] = "Zeca.eletro", Session["sector"] = "Electric", and so on.
I’ll pass my current code
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table class="table">
<tr>
<th>
ID</th>
<th>
Nome</th>
<th>
Usuário</th>
<th>
Setor</th>
<th>
Cargo</th>
<th>
Turno</th>
<th>
Ramal</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblID" runat="server" class="lbl" Text='<% #DataBinder.Eval(Container.DataItem, "id") %>'></asp:Label></td>
<td>
<asp:Label ID="lblNome" runat="server" class="lbl" Text='<% # DataBinder.Eval(Container.DataItem, "nome") %>'></asp:Label></td>
<td>
<asp:Label ID="lblUsuario" runat="server" class="lbl" Text='<% #DataBinder.Eval(Container.DataItem, "usuario") %>'></asp:Label></td>
<td>
<asp:Label ID="lblSetor" runat="server" class="lbl" Text='<% #DataBinder.Eval(Container.DataItem, "setor") %>'></asp:Label></td>
<td>
<asp:Label ID="lblCargo" runat="server" class="lbl" Text='<% #DataBinder.Eval(Container.DataItem,"cargo") %>'></asp:Label></td>
<td>
<asp:Label ID="lblTurno" runat="server" class="lbl" Text='<% #DataBinder.Eval(Container.DataItem,"turno") %>'></asp:Label></td>
<td>
<asp:Label ID="lblRamal" runat="server" class="lbl" Text='<% #DataBinder.Eval(Container.DataItem,"ramal") %>'></asp:Label></td>
<td>
<asp:LinkButton ID="btnEditar" runat="server" class="btn-sm btn-info" ToolTip="Editar" PostBackUrl="~/Exercícios/Formulario.aspx" CommandArgument='<%#Eval("id")%>' OnClick="btnEditar_Click"><span class="glyphicon glyphicon-pencil"></span></asp:LinkButton>
<asp:LinkButton ID="btnExcluir" runat="server" class="btn-sm btn-danger" ToolTip="Excluir" CommandArgument='<%#Eval("id") %>' OnClick="btnExcluir_Click"><span class="glyphicon glyphicon-remove"></span></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Follow . Cs of the page
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoCASA"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
SqlDataReader dr = null;
try
{
SqlCommand sqlSelect = new SqlCommand("SELECT id, nome, usuario, setor, cargo, turno, ramal FROM spc_funcionario_aprendiz", sqlconn);
sqlconn.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter(sqlSelect);
DataTable dt = new DataTable();
sqlDA.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
finally
{
if (dr != null)
{
dr.Close();
}
if (sqlconn != null)
{
sqlconn.Close();
}
}
}
protected void btnEditar_Click(object sender, EventArgs e)
{
Session["nome"] = "";
Session["usuario"] = "";
Session["setor"] = "";
Session["cargo"] = "";
Session["turno"] = "";
Session["ramal"] = "";
}
In the event btnEdit I want the Sessions to receive the respective result I want, already explained earlier. And that is, I hope you have understood and can help me, I thank you in advance! :)
Oops, thank you very much, I ended up testing and it worked! I did it in another way also using the form page. In the event of btnEditar put:
protected void btnEditar_Click(object sender, EventArgs e)
{
 Session["id"] = ((LinkButton)sender).CommandArgument;
 Response.Redirect("Formulario.aspx");
 }
After that in the form . Cs I put the data reading and passed to the editing Textboxes, so to do the update.. I did more things but briefly that’s it. Thanks for the help :)– Dreidel