Set CheckBoxList Item checked (selected) on GridView Edit Button Click using C# in ASP.Net

Last Reply one month ago By itsme

Posted one month ago

I am trying  to Set the checked value on edit button click  by user so that user can edit and update there record. But I dont know how to do so.

I know how to do this in dropdownlist as you can see in my code but i dont know how to do this in checkbox

Thanks

<asp:CheckBoxList ID="CheckBoxList1" runat="server">
    <asp:ListItem>Card</asp:ListItem>
    <asp:ListItem>Cash</asp:ListItem>
</asp:CheckBoxList>

 

        protected void btnEdit_Click(object sender, EventArgs e)
        {            
            try
            {
                Button btn = sender as Button;
                GridViewRow grow = btn.NamingContainer as GridViewRow;
                Id.Value = (grow.FindControl("Id") as Label).Text;
                Image img = (grow.FindControl("img") as Image);
                txt_email.Text = (grow.FindControl("lblemail") as Label).Text;
                txt_link.Text = (grow.FindControl("lblweb") as Label).Text;
                txt_img.Text = (grow.FindControl("lblimg") as Label).Text;
                txt_name.Text = (grow.FindControl("lblname") as Label).Text;
                txt_pay.Text = (grow.FindControl("lblpay") as Label).Text;
                txt_toll.Text = (grow.FindControl("lbltoll") as Label).Text;
                txt_Address.Text = (grow.FindControl("lblAddress") as Label).Text;
                Image1.ImageUrl = img.ImageUrl;
                btnUpdate.Visible = true;
                string value = (grow.FindControl("lblBname") as Label).Text;
                DropDownList1.ClearSelection();
                DropDownList1.Items.FindByText(value).Selected = true;
                string value2 = (grow.FindControl("lblcity") as Label).Text;
                DropDownList2.ClearSelection();
                DropDownList2.Items.FindByValue(value2).Selected = true;
                
                string from = (grow.FindControl("lblopen") as Label).Text;
                string[] parts = from.Split(',');
                ddlTimeFrom.ClearSelection();ddlTimeTo.ClearSelection();
                ddlTimeFrom.Items.FindByValue(parts[0].Trim()).Selected = true;
                ddlTimeTo.Items.FindByValue(parts[1].Trim()).Selected = true;  
            }
            catch(Exception ex)
            {
                Response.Write(ex);
            }
        }       

 

This question does not have replies that have been liked.