Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i need help, currently i have gridview with checkbox, i want to show confirm box when i click button with no of checkbox checked.already i try something according that its not showing the onclientclick, its only showing the function what inside the click event.

for reference pls find below my code,

XML
<ItemTemplate>
 <asp:CheckBox ID="chkSelect" runat="server" OnCheckedChanged="chk_OnCheckedChanged" AutoPostBack="true" />
</ItemTemplate>


c# code
C#
protected void btnReturn_Click(object sender, EventArgs e)
        {
            lblMsg.Text = string.Empty;

            List<int> selectedIds = GetSelectedIds();
            if (selectedIds.Count > 0)
            {
                for (int i = 0; i < selectedIds.Count; i++)
                {
                    Loan obj = engine.GetLoan(selectedIds[i]);
                    if (obj != null)
                    {
                        obj.LoanStatusDate = DateTime.Now;
                        obj.Status = LoanStatus.RETURNED.ToString();
                        obj.ProcessedBy = ConvertEngine.GetInteger(Session[SessionNames.CurrentUserID.ToString()].ToString());
                        obj.Remarks = "File is returned to Registry.";

                        if (engine.ReturnLoan(obj))
                            lblMsg.Text += WebEngine.GenerateMessage(obj.FileInfo.FRN + Constants.SuccessfulReturnedMessage, string.Empty, MessageType.Normal);
                        else
                            lblMsg.Text += WebEngine.GenerateMessage(obj.FileInfo.FRN + Constants.ErrorReturningMessage, string.Empty, MessageType.Error);
                    }
                }
            }

            BindGrid(0);


            Session[stateList] = null;
        }

        private List<int> GetSelectedIds()
        {
            List<int> selectedIds = new List<int>();
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                GridViewRow row = gvList.Rows[i];
                bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

                if (isChecked)
                {
                    selectedIds.Add(ConvertEngine.GetInteger(gvList.DataKeys[i].Value.ToString()));
                }
            }

            if (selectedIds.Count == 0)
                lblMsg.Text = WebEngine.GenerateMessage(Constants.ValidationRequiredSelectionMessage, string.Empty, MessageType.Info);

            return selectedIds;
        }

        protected void chk_OnCheckedChanged(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                GridViewRow row = gvList.Rows[i];
                bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

                if (isChecked)
                {
                    j = j + 1;
                }
            }

            btnReturn.Attributes["OnClientClick"] = "javascript : return confirm('you selected " + j.ToString() + " checkboxes.')";
            
        }


now if i click button control display the click function, but its not showing the onclientclick confirmbox.

Hope will get help soon :)

Thanks friends

Renga
Posted
Updated 28-Apr-15 19:06pm
v2
Comments
Renga.g 29-Apr-15 2:13am    
hey thanks a lot :) its working fine

You haven't written anything for showing confirmation message in button click event.
I believe you don't need write so many things to show checkbox checked count.
Check the below answer to implement the similar functionality using JQuery
Count the checked checkboxes in gridview[^]

Hope, it helps. In case this doesn't resolve your problem, let me know :)
 
Share this answer
 
Comments
Renga.g 29-Apr-15 2:14am    
thanks for your help
Use it..

C#
btnReturn.OnClientClick = "return confirm('you selected " + j.ToString() + " checkboxes.');";




Thanks & Regards,
AARIF SHAIKH
 
Share this answer
 
v2
Comments
Renga.g 29-Apr-15 2:13am    
thanks for your help :)
aarif moh shaikh 29-Apr-15 7:40am    
your welcome...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900