Hi,
This is my 1st post... I am using a checkbox in a Datalist. I am trying to display 2nd Checkbox if the 1st checkbox is checked. How do I do it in the code behind to check the "Checkbox1.Checked==True . Please find the aspx page of the file below:

<asp:DataList ID="title_dl" runat="server" DataSourceID="title_dss" DataKeyField="M_CATPAGES_ID"  >
  <ItemTemplate>
                      
                        <td><asp:Checkbox ID ="cat_title_chk" AutoPostBack="true" runat="server" Text='<%# Container.DataItem("M_CATPAGES_CAT") %>'></asp:Checkbox> </td>   

 </ItemTemplate>
                   
 </asp:DataList> 
                    
                     <asp:SqlDataSource ID="title_dss" runat="server" ConnectionString="Driver={MySQL ODBC 3.51 Driver};DATABASE=laqualite;option=0;pwd=cadt12;port=0;server=10.20.18.50;uid=root" DataSourceMode="DataReader" ProviderName="System.Data.Odbc" SelectCommand="Select M_CATPAGES_ID,M_CATPAGES_CAT from mast_catpages_tbl"></asp:SqlDataSource>

Recommended Answers

All 3 Replies

I would say this

<td><asp:Checkbox ID ="cat_title_chk" AutoPostBack="true" runat="server" OnCheckedChanged="CheckChange" Text='<%# Container.DataItem("M_CATPAGES_CAT") %>'></asp:Checkbox> </td> 
<td><asp:Checkbox ID ="chkSecond"  runat="server"  Text="Second CheckBox" Visible="False"></asp:Checkbox> </td>

Now in the source code i have this.

protected void CheckChange(object sender, EventArgs e)
        {
            CheckBox chk = ((CheckBox)sender);
            DataListItem dlItem = ((DataListItem)chk.NamingContainer);
            if (chk.Checked)
            {
                ((CheckBox)title_dl.Items[dlItem.ItemIndex].FindControl("chkSecond")).Visible = true;
            }
        }

I hope that work for you regards.

hi please help me i want to click on datalist check box and then click on find button then next page open and show me the selected checkbox.

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session[

Ok first in the button click event do this.

protected void btnClick_Click(object sender, EventArgs e)
        {
            ArrayList arr = new ArrayList();
            foreach(ListItem li in CheckBoxList1.Items)
            {
                if (li.Selected)
                {
                    arr.Add(li.Text);
                }
            }
            if (arr.Count > 0)
            {
                Session["checklist"] = arr;
                Response.Redirect("WebForm2.aspx");
            }
        }

now in the page load event from the new page.

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["checklist"] != null)
                {
                    ArrayList ar = (ArrayList)Session["checklist"];
                    for (int i = 0; i < ar.Count; i++)
                    {
                        Response.Write(System.Environment.NewLine + ar[i].ToString());
                    }
                }
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.