12 24812 Frinavale 9,735
Recognized Expert Moderator Expert
Well there are a few things to keep in mind when you're using dynamic controls.
First of all you should consider the scope of the dynamic controls.
If you create a control in a function (like a button, table, radiobutton...) then the control only exists within that function.....it will be rendered on the page (because you added it to the placeholder) but when the request comes back to the server the controls declared in the function will no longer exist.
This means that dynamic controls have to have a scope for the whole page...you cannot simply declare them inside a method.
The other thing you have to consider is the ASP Page Life Cycle....
Please take a look this article about how to use dynamic controls in ASP.NET....
I don't think you need to use dynamic controls for your application.
You should be using a RadioButtonList instead of dynamically creating individual RadioButtons. You can assign a DataSource to the RadioButtonList . The RadioButtonList will automatically create the necessary RadioButtons for the DataSource that it's bound to.
This means that your RadioButtonList is not dynamic, but the datasource that it's bound to IS....so the content of the RadioButtonList is dynamic.
For example check out this article on how to bind a RadioButtonList to a Custom Object...if you're just using a DataBase then it's even easier :)
This will save you a lot of problems.
Hi Frinavale.
Thank you for your reply.
Well, the outcome i want to get is as shown in the image below: ![](/images/imgserve.php?url=http://i1002.photobucket.com/albums/af143/ive1122/outcome.jpg)
I don't think that it can be done (column by column) by using radio button list.
At first, i was using gridview to generate the survey. However, i was unable to do it using data source due to dynamic columns number. Besides, the header for the radio button is also generated dynamically. Therefore, i have no choice but to go for dynamic controls generation.
Do you have any idea or solution for this?
I very appreciated your help :)
In the GridView create the the template like this <asp:TemplateFi eld HeaderText="Ass ign">
<ItemTemplate >
<input ID="Radio1" type="radio" name="RdBtn" value='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateFie ld>
Code Behind after post back. Get the value as below. you can get the value
of Radio button with name. bcz in same group the name is same for each.
and the following code will get the value of selected Radio Button string selectedRadioBu tton = "";
selectedRadioBu tton = Request.Form["RdBtn"];
Hi,
im working on similar project and wonder if you can help me. Can you post some sample code?
i can help you and can post sample code, when you post your Question.
Hi,
I need to populate the table to display as below. All the questions and answers is store in a oracle database. Question | Answer 1 | Answer 2 | Answer 3 | Answer 4 | Answer 5
How do i format so it will display as above?
How do I loop through the radio button to find answer then insert it back to the database?
I tried to format the question by using Response.write( ) but when I click on submit answer it does not do anything and I could not use the FindControl to find the radio button in code behind.
i think you have two tables one for questions and other for answers .
if this is the case use inner join and then convert it to pivot table. you will get the desired result for formatting.
and for the radio button. u can do it with javascript . implement onclick event on radio button. and store the clicked radio buttons value in hidden field and get the value from hidden field in code behind. and store it to database.
Thank you you reply. Since the question and answer are dynamic create how do i know how many hidden field to create?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mitch-co2 |
last post by:
What I am trying to do is when someone clicks on the YES radio button I
want the text field called MYTEXT to equal the text field named DATE.
The below code works as long as I do NOT UN-COMMENT the NO radio
button, once I do that it will not work.
Any help would be greatly appreciated.
Mitch
|
by: johnsuth |
last post by:
I want to produce a trivial demonstration of dynamic modification.
I thought that pressing a button might change its color.
I studied O'Reillys books and successfully created the button with a fancy
style, but the onclick fails to do anything no matter what permutation of
parameters I try.
<input type=button style=background-color:yellow;color:blue;font-family:Arial;font-style:italic;font-weight:bold name="xyz" value="CHANGE COLOUR"...
|
by: PCH |
last post by:
I have an c# asp.net (.net 1.1) web page, viewstate on.
The problem I am having is on the button click postback to update.
Heres the situation:
I have an asp table that has 1 header row.
On load I loop through a count, say 0 to 3, and dynamically build rows, into
the asp table.
|
by: darrel |
last post by:
I'm using some standard HTML radio buttons (to allow finer javascript
interaction) on a web page and would like to catch the selected item on
postback. Since they are all ID's uniquely, is there a way to grab only the
selected item's value? Or do I need to write an if/then statement to figure
out which one is selected?
Sample:
<input runat="server" id="radio1" name="category" />
<input runat="server" id="radio2" name="category" />
|
by: david |
last post by:
I have developed a web form by using visual Studio. My question is:
(1) what is the problem?
(2) what is right way to do it?
In the form, there are labels with id:
lblWear, lblColor, and lblQuality.
Now I need to assign values to those label dynamically.
I have JavaScript:
function regTriples(id){
if (id==1){
| |
by: saurabh |
last post by:
Can anybody tell me how to change the value of an html control from the
c#....
eg i hv one asp.net radio button control and one html hidden
variable...
so on page load in case the radio button is checked i want to set this
hidden variable to 1 else 0...
I am not getting what to write in Page_Load(object sender,
System.EventArgs e) function to change the value of this html
variable...
|
by: Mufasa |
last post by:
I have a couple of radio buttons that make various things appear/disappear
on the screen through JavaScript. All works great. Problem is I'll click a
radio button, something will appear, I reload the page for other reasons and
the item disappears. The reason it disappears is I have to set the state
initially to invisible so it doesn't show up initially.
The radio buttons are html radio buttons not aspx radio buttons so I can
have the...
|
by: mcelary |
last post by:
When the user clicks a radio button it creates a postback where I add a button control dynamically. My problem is I cannot get the dynamically added button to work with on an click event. The button was created in code behind page.
Public Sub rosterAddControls()
Dim myBtn As New Button()
myBtn.Style.Item("z-index") = "100"
myBtn.Style.Item("position") = "absolute"
myBtn.Style.Item("top") = (x - 30) & "px"
...
|
by: tommymo |
last post by:
Hi everyone I'm new to this site and the world of ASP.Net C# programming. I have been learning controls and integrating them with a SQL database. So far I have been able to move along and understand static controls. However I would like to move on to attempt to create some dynamic controls. So I set out to work with a radiobuttonlist questionnaire. I have a database and in that DB I have 2 tables one which holds the questions and the other...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |