locked
Show/hide a table column on unchecking a checkbox insider repeater control RRS feed

  • Question

  • User-190697402 posted

    Hi ,

    when i uncheck a customer from the checkbox list  inside a repeater it should display another column named remarks,where i can enter the reason for unchecking that customer.

    i should be able to display the column header also(th).

    How can i acheive this in server side,i  dont want javascript/jquery coding.

    Any help would be appreciated.

    Thanks.

    Tuesday, June 30, 2020 3:51 AM

Answers

  • User288213138 posted

    Hi teenajohn1989,

    teenajohn1989

    when i uncheck the check box,its not even enetring to this 'chkHODApproval_CheckedChanged' function.

    teenajohn1989

    <asp:CheckBox ID="chkHODApproval" Checked='<%# Convert.ToString(Eval("hod_approval")) == "Yes"?true:false%>' runat="server" OnCheckedChanged="chkHODApproval_CheckedChanged" />

    You should add a AutoPostBack Property in the checkbox. 

    The CheckBox. AutoPostBack Property gets or sets a value indicating whether the CheckBox state automatically posts back to the server when clicked.

    <asp:CheckBox ID="chkHODApproval" Checked='<%# Convert.ToString(Eval("hod_approval")) == "Yes"?true:false%>' runat="server"
    AutoPostBack="true" OnCheckedChanged="chkHODApproval_CheckedChanged" />

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 1, 2020 7:12 AM

All replies

  • User288213138 posted

    Hi teenajohn1989,

    when i uncheck a customer from the checkbox list  inside a repeater it should display another column named remarks,where i can enter the reason for unchecking that customer.

    According to your description, I couldn’t understand your requirement clearly.

    Whis is  display another column named remarks and the column header also(th)?

    But i made demo for you as a reference.

    <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
                            <asp:ListItem Selected="True">customer1</asp:ListItem>
                            <asp:ListItem Selected="True">customer2</asp:ListItem>
                            <asp:ListItem Selected="True">customer3</asp:ListItem>
                            <asp:ListItem Selected="True">customer4</asp:ListItem>
                            <asp:ListItem Selected="True">customer5</asp:ListItem>
                        </asp:CheckBoxList>
                    </ItemTemplate>
                </asp:Repeater>
    
    
      protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
                    dt.Rows.Add(1, "n1", "c1");
                    Repeater1.DataSource = dt;
                    Repeater1.DataBind();
                }
            }
    
            protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                foreach (RepeaterItem item in Repeater1.Items)
                {
                    CheckBoxList cbl = (CheckBoxList)item.FindControl("CheckBoxList1");
                    foreach (ListItem item1 in cbl.Items)
                    {
                        if (item1.Selected==false)
                        {
                            if(item1.Text== "customer1")
                            {
                                //you can do something after uncheck the customer1
                            }
                        }
                    }
    
                }
            }

    The result:

    Best regards,

    Sam

    Tuesday, June 30, 2020 10:11 AM
  • User-190697402 posted

    Hi Sam,

    Here is my code

    <asp:Repeater ID="rpPreEventCompList" runat="server" OnItemDataBound="rpPreEventCompList_ItemDataBound">
                                <HeaderTemplate>
                                    <table border="1" style="margin:25px 10px;">
                                        <tr>
                                            <th style="text-align:center;">Invite Tier</th>
                                            <th style="text-align:center;">Event Name</th>
                                            <th style="text-align:center;">Invitee Organisation/Company Name</th>
                                            <th style="text-align:center;">Invitee Name</th>
                                            <th style="text-align:center;">Email Address</th>
                                            <th style="text-align:center;">Contact</th>
                                            <th runat="server" id="thSalesChannel" style="text-align:center;">Sales Channel Head</th>
                                            <th runat="server" id="thSalesManager" style="text-align:center;">Sales Manager</th>
                                            <th runat="server" id="thSalesPerson" style="text-align:center;">Sales Person</th>
                                            <th style="text-align:center;">Justification</th>
                                            <th style="text-align:center;">Amount Consumed</th>
                                            <th style="text-align:center;">Balance Amount</th>
                                            <th runat="server" id="thHODApproval" style="text-align:center;">
                                                HOD Approval
                                                <asp:CheckBox ID="chkAllHODApprv" runat="server" AutoPostBack="True" OnCheckedChanged="chkAllHODApprv_CheckedChanged" />
                                            </th>
                                            <th runat="server" id="thHODRemarks" style="text-align:center;">HOD Remarks</th>
                                            <th runat="server" id="thMDApproval" style="text-align:center;">
                                                MD Approval
                                                <asp:CheckBox ID="chkAllMDApprv" runat="server" />
                                            </th>
                                            <th runat="server" id="thMDRemarks" style="text-align:center;">MD Remarks</th>
                                            <th runat="server" id="thCOApproval" style="text-align:center;">
                                                Compliance Officer Approval
                                                <asp:CheckBox ID="chkAllCOApprv" runat="server" />
                                            </th>
                                            <th runat="server" id="thCORemarks" style="text-align:center;">Compliance Officer Remarks</th>
                                            <th style="text-align:center;">Status</th>
                                            <th style="text-align:center;">Action</th>
                                         </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                        <tr>
                                            <td class="auto-style2">
                                                <asp:Label ID="lblInviteTier" runat="server" Text='<%# Eval("invitee_tier") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style6">
                                                <asp:Label ID="lblEventName" runat="server" Text='<%# Eval("event_name") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style6">
                                                <asp:Label ID="lblCompanyName" runat="server" Text='<%# Eval("invitee_organisation_name") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblInviteeName" runat="server" Text='<%# Eval("invitee_first_name") + " " + Eval("invitee_last_name") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblInviteeEmailAddress" runat="server" Text='<%# Eval("email_address") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblInviteeContact" runat="server" Text='<%# Eval("contact_no") %>'></asp:Label>
                                            </td>
                                            <td runat="server" id="tdSalesChannelHead" class="auto-style5">
                                                <asp:Label ID="lblSalesChannelHead" runat="server" Text='<%# Eval("sales_channel") %>'></asp:Label>
                                            </td>
                                            <td runat="server" id="tdSalesManager"  class="auto-style5">
                                                <asp:Label ID="lblSalesManager" runat="server" Text='<%# Eval("sales_manager") %>'></asp:Label>
                                            </td>
                                            <td runat="server" id="tdSalesPerson" class="auto-style5">
                                                <asp:Label ID="lblSalesPerson" runat="server" Text='<%# Eval("sales_person") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblJustification" runat="server" Text='<%# Eval("justification") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblAmountConsumed" runat="server" Text='<%# Eval("total_utilization") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblBalanceAmount" runat="server" Text='<%# Eval("balance_amount") %>'></asp:Label>
                                            </td>
                                            <td runat="server" id="tdHODApproval" class="auto-style5">
                                                <asp:CheckBox ID="chkHODApproval" Checked='<%# Convert.ToString(Eval("hod_approval")) == "Yes"?true:false%>' runat="server" OnCheckedChanged="chkHODApproval_CheckedChanged" /> 
                                            </td>
                                            <td runat="server" id="tdHODRemarks" class="auto-style5">
                                                <asp:Label ID="lblHODRemarks" runat="server" Text='<%# Eval("hod_remarks") %>'></asp:Label>
                                            </td>
                                            <td runat="server" id="tdMDApproval" class="auto-style5">
                                                <asp:CheckBox ID="chkMDApproval" Checked='<%# Convert.ToString(Eval("md_approval")) == "Yes"?true:false%>' runat="server" />                                             
                                            </td>
                                            <td runat="server" id="tdMDRemarks" style="display:none;" class="auto-style5">
                                                <asp:Label ID="lblMDRemarks" runat="server" Text='<%# Eval("md_remarks") %>'></asp:Label>
                                            </td>
                                            <td runat="server" id="tdCOApproval" style="display:none;" class="auto-style5">
                                                <asp:CheckBox ID="chkCOApproval" Checked='<%# Convert.ToString(Eval("compliance_officer_approval")) == "Yes"?true:false%>' runat="server" />                                             
                                            </td>
                                            <td runat="server" id="tdCORemarks" style="display:none;" class="auto-style5">
                                                <asp:Label ID="lblCORemarks" runat="server" Text='<%# Eval("compliance_officer_remarks") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("status") %>'></asp:Label>
                                            </td>
                                            <td class="auto-style5">
                                                <asp:LinkButton ID="lnkbtnEditCustomer" OnCommand="btnPreEventInviteeId_Click" CommandArgument='<%# Eval("email_address") %>' Text="Edit" runat="server"></asp:LinkButton> 
                                            </td>
                                        </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table>
                                </FooterTemplate>
                            </asp:Repeater>

    Here is my code for functions declared

    protected void rpPreEventCompList_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if(Session["userRole"].ToString() == "superadmin")
                {
                    if (e.Item.ItemType == ListItemType.Header)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesChannel")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesManager")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesPerson")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODApproval")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thMDApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thMDRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thCOApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thCORemarks")).Visible = false;
                    }
                    else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesChannelHead")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesManager")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesPerson")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdHODApproval")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdHODRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdMDApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdMDRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdCOApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdCORemarks")).Visible = false;
                    }
                }
    
                if (Session["userRole"].ToString() == "salesmanagers")
                {
                    if (e.Item.ItemType == ListItemType.Header)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesChannel")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesManager")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesPerson")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thMDApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thMDRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thCOApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thCORemarks")).Visible = false;
                    }
                    else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesChannelHead")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesManager")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesPerson")).Visible = true;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdHODApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdHODRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdMDApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdMDRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdCOApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdCORemarks")).Visible = false;
                    }
                }
    
                if (Session["userRole"].ToString() == "salespersons")
                {
                    if (e.Item.ItemType == ListItemType.Header)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesChannel")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesManager")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thSalesPerson")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thMDApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thMDRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thCOApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thCORemarks")).Visible = false;
                    }
                    else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesChannelHead")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesManager")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdSalesPerson")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdHODApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdHODRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdMDApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdMDRemarks")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdCOApproval")).Visible = false;
                        ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("tdCORemarks")).Visible = false;
                    }
                }
    
            }
    protected void chkAllHODApprv_CheckedChanged(object sender, EventArgs e)
            {
                foreach (RepeaterItem row in rpPreEventCompList.Items)
                { 
                    if (row.ItemType != ListItemType.Header)
                    {
                        CheckBox chkSelect = (CheckBox)row.FindControl("chkHODApproval");
                        if (chkSelect.Checked == false)
                        {
                            chkSelect.Checked = true;
                        }
                        else
                        {
                            chkSelect.Checked = false;
                        }
                    }
                }
            }
    
           protected void chkHODApproval_CheckedChanged(object sender, EventArgs e)
           {
                foreach (RepeaterItem row in rpPreEventCompList.Items)
                {
                    if (row.ItemType == ListItemType.Header)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)row.FindControl("thHODRemarks")).Visible = true;
                        
                    }
                    if (row.ItemType != ListItemType.Header)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)row.FindControl("tdHODRemarks")).Visible = true;
                    }
                }
    
           }

    when i uncheck the check box,its not even enetring to this 'chkHODApproval_CheckedChanged' function.

    Please help me to figure out this.Thanks!

    Wednesday, July 1, 2020 4:13 AM
  • User288213138 posted

    Hi teenajohn1989,

    teenajohn1989

    when i uncheck the check box,its not even enetring to this 'chkHODApproval_CheckedChanged' function.

    teenajohn1989

    <asp:CheckBox ID="chkHODApproval" Checked='<%# Convert.ToString(Eval("hod_approval")) == "Yes"?true:false%>' runat="server" OnCheckedChanged="chkHODApproval_CheckedChanged" />

    You should add a AutoPostBack Property in the checkbox. 

    The CheckBox. AutoPostBack Property gets or sets a value indicating whether the CheckBox state automatically posts back to the server when clicked.

    <asp:CheckBox ID="chkHODApproval" Checked='<%# Convert.ToString(Eval("hod_approval")) == "Yes"?true:false%>' runat="server"
    AutoPostBack="true" OnCheckedChanged="chkHODApproval_CheckedChanged" />

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 1, 2020 7:12 AM
  • User-190697402 posted

    Hi Sam,

    Thank you so much !!

    i'm having issue with displaying the header of that column,

    and also can you suggest how to display the the Remarks textfield only for the unchecked checkbox. Currently when im unchecking one checkbox,the remarks column is showing textfields for all the rows including the checked ones.Should i need to pass a uniqueid for this?

    <td runat="server" id="tdHODApproval" class="auto-style5">
                                                <asp:CheckBox ID="chkHODApproval" AutoPostBack="true" Checked='<%# Convert.ToString(Eval("hod_approval")) == "Yes"?true:false%>' runat="server" OnCheckedChanged="chkHODApproval_CheckedChanged" /> 
                                            </td>
                                            <td runat="server" id="tdHODRemarks" class="auto-style5">                                            
                                                <asp:TextBox ID="txtHODRemarks" runat="server"  Text='<%# Eval("hod_remarks") %>' TextMode="MultiLine"></asp:TextBox>
                                            </td>

    Thanks in advance.

    Wednesday, July 1, 2020 8:17 AM
  • User288213138 posted

    Hi teenajohn1989,

    how to display the the Remarks textfield only for the unchecked checkbox. Currently when im unchecking one checkbox,the remarks column is showing textfields for all the rows including the checked ones.

    Which column is Remarks textfield?

    Do you mean that when you unchecking one checkbox, you only want the value in this row to be displayed?

    Best regards,

    Sam

    Wednesday, July 1, 2020 9:27 AM
  • User-190697402 posted

    Hi Sam,

    Here is the scenario,

    HOD Approval

    (check all )

    This column will be hidden
    Checkboxes with checked status
    Checkboxes with checked status
    Checkboxes with checked status
    Checkboxes with checked status
    Checkboxes with checked status

     

    When any of the checkbox is unchecked,the hidden column should be made visible with textfield enabled only for that unchecked row.

    HOD Approval

    (check all )

    This column will be displayed
    Checkboxes with checked status
    unchecked checkbox with textfield to enter the reason for unchecking
    Checkboxes with checked status
    Checkboxes with checked status
    unchecked checkbox with textfield to enter the reason for unchecking

    Hope you are clear on my problem.

    Thanks!

    Wednesday, July 1, 2020 10:19 AM
  • User-190697402 posted

    Hi Sam,

    I managed to get it done.

    But the Column  header for remarks  is not displaying. could you please let me know  is there any problem with this code ?

    if (row.ItemType == ListItemType.Header)
                    {
                        ((System.Web.UI.HtmlControls.HtmlTableCell)row.FindControl("thHODRemarks")).Visible = true;
                        
                    }

    Thanks in Advance!

    Wednesday, July 1, 2020 2:42 PM
  • User288213138 posted

    Hi Hi teenajohn1989,

    But the Column  header for remarks  is not displaying. could you please let me know  is there any problem with this code

    Can you show me your latest code?

    ((System.Web.UI.HtmlControls.HtmlTableCell)e.Item.FindControl("thHODRemarks")).Visible = false;

    I noticed that you have set visible of thHODRemarks to false.

    Best regards,

    Sam

    Thursday, July 2, 2020 7:03 AM
  • User-190697402 posted

    Hi Sam,

    I fixed it.

    rpPreEventCompList.Controls[0].Controls[0].FindControl("thHODRemarks").Visible = true;

    Thanks for your response.

    Thursday, July 2, 2020 10:12 AM