<< Click to Display Table of Contents >> ListView - percorrer itens |
![]() ![]() ![]() |
Default.aspx.
<asp:ListView ID="lvDados" runat="server" onitemdatabound="lvDados_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblID" runat="server">9999</asp:Label>
</ItemTemplate>
</asp:ListView>
Default.aspx.cs
protected void btnSim_Click(object sender, EventArgs e)
{
// percorre os itens da ListView e adiciona num string para usar no sql
string ids = "";
foreach (ListViewDataItem itemRow in lvDados.Items)
{
Label lblID = itemRow.FindControl("lblID") as Label;
ids += lblID.Text + ",";
}
Conexao.ExecSQL("update tarefa.tb_tarefa set tp_status = 1 where cd_tarefa in (" + ids + "0)");
Response.Redirect("Default.aspx");
}