How to found CheckBox ID

Total Post:117

Points:821
C# 
 1102  View(s)
Ratings:
Rate this:

I want to check a checkbox after finding that it is checked in database. I'm trying this:

string chkboxbit = String.Empty;
CheckBox cb = new CheckBox();
chkboxbit = "ct100$ContentPlaceHolder1_chk" + item+ "" + i;
cb = (CheckBox)Page.FindControl(chkboxbit.ToString());
cb.Checked = false;

But I'm getting cb value null on debugging.

  1. Post:101

    Points:709
    Re: How to found CheckBox ID

    Hi jay

    I got it... and it works fine...

    chkboxbit = "chk" + item + "" + i;
    ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
    cb = ((CheckBox)cph.FindControl(chkboxbit));
    if (cb != null)
        cb.Checked = false;

    Thnks to all for their effort. and Thanks Kyojimaru.

      Modified On Apr-09-2018 12:08:52 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!