mardi 24 janvier 2017

get selected checkboxes in listview with button

There is a listview. Listview ID:myListView. There is a hiddenField in listview(in itemTemplate) HiddenField ID:hfID. There is a checkbox in listview(in itemTemplate) Checkbox ID:checkBoxSec And there is a button out of listview. Button ID:btnConfirmSelected

My purpose: I would like to get selected checkbox when i click this asp button.

Now, i am sharing aspx page first and then aspx.cs (code behind codes)

1-aspx side

<asp:ListView ID="myListView" runat="server" OnItemCommand="listView_OnItemCommand"
            OnItemDataBound="listView_ItemDataBound">
            <LayoutTemplate>
                <table id="listViewRecordsTable" cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th style="text-align: left;">
                                <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" onchange="CheckAll(this);" />
                            </th>

                            <th style="text-align: left;">
                                süreç no
                            </th>

                        </tr>
                    </thead>
                    <tbody>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                    </tbody>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr class="odd gradeX" id="<%# Eval("ID").ToString() == "BOS" ? "" : Eval("ID")%>">
                    <td>
                        <asp:CheckBox ID="checkBoxSec" runat="server" CssClass="checkBoxExample" />
                    </td>


                    <td>

                            <%# Eval("surecID").ToString() == "BOS" ? "" : Eval("surecID")%>

                    </td>

                </tr>
            </ItemTemplate>

        </asp:ListView>

2-aspx.cs side (code behind)

protected void btnConfirmSelected_Click(object sender, EventArgs e) { try {

        foreach (var item in myListView.Items)

        {

            if (item.ItemType == ListViewItemType.DataItem)

            {


                HiddenField hfID = item.FindControl("hfID") as HiddenField;
                CheckBox checkBoxSec = item.FindControl("checkBoxSec") as CheckBox;

                if (checkBoxSec.Checked)
                {
                    //some tasks in here. i put debug point to here. and then i click button after i select some checkbox. but debug never comes here. 
                }
            }
        }

    }
    catch (Exception ex)
    {
        labelResult.Text = ex.ToString();
    }

}

Can anyone help me please; Where is the mistake or any missing part? I put debug point to here:

                    if (checkBoxSec.Checked)
                {
                    //some tasks in here. i put debug point to here. and then i click button after i select some checkbox. but debug never comes here. 
                }

but never comes here. but i am clicking button after i select some checkbox. thanks a lot.




Aucun commentaire:

Enregistrer un commentaire