i create dynamic checkboxes in coloum of table(<td id="trial" runat="server"></td>) from selecting quantity from dropdwonlist.
well creating dynmic checkbox is not an issue..

well the issue is tht i am not able to check whether the Checkboxes is checked or not on a Button click....

the functiion used for generating dyamic checkbox..

protected void ddlList_SelectedIndexChanged(object sender, EventArgs e)  
    {
int no=convert.toint32(ddlist.selectedvalue);  


for(int i=1;i=<no;i++)
{
checkbox ch=new checkbox()
ch.ID="chk_t"+i;
ch.text="trl"

trial.controls.add(ch);

}
}

the function where i check whether checkboxes is checked

protected void btnSave_Click(object sender, EventArgs e)  
    {  
list<string> status_tn=new list<string>();

for (int j = 1; j <= no; j++)
            {
               trialid = "chk_t" + j;

             
              CheckBox  checks=(CheckBox)trial.FindControl(trialid);

       


                if (checks.Checked)
                {
                    
                    status_tn.Add("Trial");
                    

                }
}
          }

in this function i get error :
:System.NullReferenceException was unhandled by user code

Message="Object reference not set to an instance of an object."

Source="App_Web_pm_-zh7o"

StackTrace:

at btn_save_Click(Object sender, EventArgs e) in d:\Dot Net App\Talents\types_seeb.aspx.cs:line 325

at System.Web.UI.WebControls.Button.OnClick(EventArgs e)

at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


could someone help me with this..... i've been stuck with this for hours

One thing I notice is that in your checking code, you're running a for loop using the "no" variable that is not defined anywhere in the local scope. Define that and let's see how it works.

The reason is that you have defined "no" valriable locally in SelectedIndexChange Event of dropdown.

int no=convert.toint32(ddlist.selectedvalue);

This is not really a problem. If you have defined "no" variable globally then you will not get error but also you will not get value of "no" variable because of Postback of page by changing value from Dropdown.

So one way is Store value of "no" variable in ViewState in SelectedIndexChange event and then in Click event of Save button, Convert ViewState value in Integer and iterate through the loop.

Other way is defined "no" variable globally with Static keyword.

I hope it will work for you..

Let us know if it will not work for you..

i create dynamic checkboxes in coloum of table(<td id="trial" runat="server"></td>) from selecting quantity from dropdwonlist.
well creating dynmic checkbox is not an issue..

well the issue is tht i am not able to check whether the Checkboxes is checked or not on a Button click....

the functiion used for generating dyamic checkbox..

protected void ddlList_SelectedIndexChanged(object sender, EventArgs e)  
    {
int no=convert.toint32(ddlist.selectedvalue);  


for(int i=1;i=<no;i++)
{
checkbox ch=new checkbox()
ch.ID="chk_t"+i;
ch.text="trl"

trial.controls.add(ch);

}
}

the function where i check whether checkboxes is checked

protected void btnSave_Click(object sender, EventArgs e)  
    {  
list<string> status_tn=new list<string>();

for (int j = 1; j <= no; j++)
            {
               trialid = "chk_t" + j;

             
              CheckBox  checks=(CheckBox)trial.FindControl(trialid);

       


                if (checks.Checked)
                {
                    
                    status_tn.Add("Trial");
                    

                }
}
          }

in this function i get error :
:System.NullReferenceException was unhandled by user code

Message="Object reference not set to an instance of an object."

Source="App_Web_pm_-zh7o"

StackTrace:

at btn_save_Click(Object sender, EventArgs e) in d:\Dot Net App\Talents\types_seeb.aspx.cs:line 325

at System.Web.UI.WebControls.Button.OnClick(EventArgs e)

at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


could someone help me with this..... i've been stuck with this for hours

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.