Checbox Selected List View

Asked

Viewed 233 times

0

I have a ListView where at the end I have a CheckBox referencing my data. I need to create a button that fires a method that traverses the Checkbox selected and take its value. How to do this method?

                    <asp:ListView ID="lstGerenciamentoFrmAnaliseEficacia"  runat="server" ItemPlaceholderID="itemPlaceholder"  OnPagePropertiesChanged="lstGerenciamentoFrmAnaliseEficacia_PagePropertiesChanged" DataKeyNames="QO_CODIGO, QAO_CODIGO, AAO_CODIGO">

                            <LayoutTemplate>

                                <div class="table-responsive">
                                    <table class="table table-striped table-bordered table-condensed table-hover" runat="server" id="tblGerenciamentoFrmAnaliseEficacia">
                                        <thead>
                                            <tr class="title" runat="server">
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Ocorrência</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Setor Notificado</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Tipo</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Data Ocorrência</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Análise</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Ação</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Título</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Status</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Execução</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom">Responsável</th>
                                                <th runat="server" class="text-center" style="vertical-align: bottom"></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr runat="server" id="itemPlaceholder" />
                                        </tbody>
                                    </table>
                                </div>

                                <div class="text-center">
                                    <asp:DataPager runat="server" ID="pgrGerenciamentoFrmAnalises" PagedControlID="lstGerenciamentoFrmAnalises">
                                        <Fields>
                                            <asp:TemplatePagerField>
                                                <PagerTemplate>
                                                    <p><strong><%# Container.TotalRowCount %></strong> registro(s) encontrado(s).</p>
                                                </PagerTemplate>
                                            </asp:TemplatePagerField>
                                            <asp:NextPreviousPagerField
                                                ButtonCssClass="btn btn-default btn-xs"
                                                ShowFirstPageButton="true"
                                                ShowPreviousPageButton="false"
                                                ShowNextPageButton="false"
                                                ShowLastPageButton="false"
                                                FirstPageText="Primeira" />
                                            <asp:NumericPagerField
                                                NumericButtonCssClass="btn btn-default btn-xs"
                                                NextPreviousButtonCssClass="btn btn-default btn-xs"
                                                CurrentPageLabelCssClass="btn btn-primary btn-xs" />
                                            <asp:NextPreviousPagerField
                                                ButtonCssClass="btn btn-default btn-xs"
                                                ShowFirstPageButton="false"
                                                ShowPreviousPageButton="false"
                                                ShowNextPageButton="false"
                                                ShowLastPageButton="true"
                                                LastPageText="Última" />
                                        </Fields>
                                    </asp:DataPager>
                                </div>

                            </LayoutTemplate>


                            <EmptyDataTemplate>
                                <tr>
                                    <td>Nenhum registro foi encontrado.</td>
                                </tr>
                            </EmptyDataTemplate>

                            <EmptyItemTemplate>
                                <td />
                            </EmptyItemTemplate>

                            <ItemTemplate>
                                <tr>
                                    <td class="col-md-1 text-right" style="vertical-align: middle"><%# Eval("QO_CODIGO") %></td>
                                    <td class="col-md-3 text-center" style="vertical-align: middle"><%# Eval("ST_DESCRICAO") %></td>
                                    <td class="col-md-2 text-center" style="vertical-align: middle"><%# Eval("QTO_DESCRICAO") %></td>
                                    <td class="col-md-2 text-center" style="vertical-align: middle"><%# Convert.IsDBNull(Eval("QO_DATAREGISTRO")) ? "N/A" : Convert.ToDateTime(Eval("QO_DATAREGISTRO")).ToString("dd/MM/yyyy") %></td>
                                    <td class="col-md-1 text-right" style="vertical-align: middle"><%# Eval("QAO_CODIGO") %></td>
                                    <td class="col-md-1 text-right" style="vertical-align: middle"><%# Eval("AAO_CODIGO") %></td>
                                    <td class="col-md-4 text-center" style="vertical-align: middle"><%# Eval("AAO_TITULO") %></td>
                                    <td class="col-md-1 text-right" style="vertical-align: middle"><%# Eval("AAO_STATUS").Equals("P") ? "Prevista" : Eval("AAO_STATUS").Equals("C") ? "Concluída" : Eval("AAO_STATUS").Equals("E") ? "Eficaz" : Eval("AAO_STATUS").Equals("I") ? "Ineficaz" : string.Empty %></td>
                                    <td class="col-md-1 text-right" style="vertical-align: middle"><%# Convert.IsDBNull(Eval("AAO_DATAEXECUCAO")) ? "N/A" : Convert.ToDateTime(Eval("AAO_DATAEXECUCAO")).ToString("dd/MM/yyyy") %></td>
                                    <td class="col-md-1 text-center" style="vertical-align: middle"><%# Eval("USU_NOME") %></td>
                                    <td class="col-md-1 text-center" style="vertical-align: middle"><asp:CheckBox value='<%# Eval("QO_CODIGO") + "," + Eval("QAO_CODIGO")  + "," + Eval("AAO_CODIGO")%>' runat="server" id="chkFrmAnaliseEficacia" /></td>
                                </tr>
                            </ItemTemplate>

                        </asp:ListView>

1 answer

1

If I understood your question, there are several ways to do this, one of the ways is to scroll through the listview, checking if it has checkbox enabled, and take its value, follow an example code:

//Evento do Botão
protected void btValores_Click( object sender, EventArgs e )
{
  foreach( ListViewDataItem item in ListView1.Items )
  {
    var check = item.FindControl("chkFrmAnaliseEficacia") as CheckBox;
    if(check != null && check.Checked )
    {
      string value = check.Value;
    }
  }
}

Browser other questions tagged

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