473,385 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem with accessing control created dynamically

Dear All,

I am using asp.net2.0, C#, sql2005 using Visual studio 2005

Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created dropdownlistbox and label dynamically through loop and assign id as dropdownlist + no of iteration. Now my question is how I access these control as when I am accessing one of the control I am getting nullobjectreference error stating “Object reference not set to an instance of an object.”
I created control as

Foreach(listitem)
{

//…….
Label label = new Label();
DropDownList dropdownlist = new DropDownList();
//assinging id
label.ID = "label" + i.ToString() ;
dropdownlist.ID = "dropdownlist" + i.ToString() ;

}
And I am accessing it through

cmd.Parameters.Add("@para1", SqlDbType.VarChar).Value = Page.FindControl("label1").ToString() ;
cmd.Parameters.Add("@value1", SqlDbType.VarChar).Value = Page.FindControl("dropdownlist1").ToString();

and my second question is how do i access selected value in dropdownlist1(dynamically created control) Please guide me

Thanks
Jul 26 '07 #1
4 1467
krris
10
Dear All,

I am using asp.net2.0, C#, sql2005 using Visual studio 2005

Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created dropdownlistbox and label dynamically through loop and assign id as dropdownlist + no of iteration. Now my question is how I access these control as when I am accessing one of the control I am getting nullobjectreference error stating “Object reference not set to an instance of an object.”
I created control as

Foreach(listitem)
{

//…….
Label label = new Label();
DropDownList dropdownlist = new DropDownList();
//assinging id
label.ID = "label" + i.ToString() ;
dropdownlist.ID = "dropdownlist" + i.ToString() ;

}
And I am accessing it through

cmd.Parameters.Add("@para1", SqlDbType.VarChar).Value = Page.FindControl("label1").ToString() ;
cmd.Parameters.Add("@value1", SqlDbType.VarChar).Value = Page.FindControl("dropdownlist1").ToString();

and my second question is how do i access selected value in dropdownlist1(dynamically created control) Please guide me

Thanks

Hi
u r declare the label and Drop down in loop so when loop is over object scop is also over. if u declare label and dropdown out of loop with array then it will help u.
Jul 26 '07 #2
Hello sir ! can u provide me with the code for creating a text box control array when a button is clicked ?
Aug 10 '07 #3
TRScheel
638 Expert 512MB
Hello sir ! can u provide me with the code for creating a text box control array when a button is clicked ?
What solutions have you tried? Have you considered a hidden frame that is visible once the button is clicked, then disposed of when no longer needed?
Aug 10 '07 #4
TRScheel
638 Expert 512MB
my second question is how do i access selected value in dropdownlist1(dynamically created control) [/b] Please guide me

Thanks

You need to cast the found control to the proper type.

Expand|Select|Wrap|Line Numbers
  1. ((DropDownList)Page.FindControl("MyDropDownList"))
Aug 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
3
by: fumihiko | last post by:
Hi, I created an activex control (C++), and it uses another COM dll (C++). This COM dll links with a static library that dose some calculation. (both are debug multithreaded dll) I created a...
3
by: Eric | last post by:
I have built a composite user web control that I want to create dynamically. The form will contain a variable number of these controls and as well some of the contents of the user web control...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
2
by: Richard Lionheart | last post by:
Hi All, I generated a WebForm and created a Virtual Directory for it IIS. But I got an error message (shown below) saying something like my app lacked appropriate privileges. David Wang...
5
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet...
6
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.