473,396 Members | 1,799 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,396 software developers and data experts.

Dynamic radio or checkbox within repeater

New to programming and am struggling on the following:

I've got a repeater that dynamically creates a series of questions. The questions come from a database and can be either answertype 1 or 2 depending on whether they should be a radio button or a checkbox. The radio buttons and checkboxes themselves have several related variables that are being populated by their own Eval statements. I tried this as a code behind function that would write the full radio or checkbox string but it kept getting hung up on the internal eval statements.

basically I'm trying to get something like the following on the client side:

<%# iAnswerType = (Convert.ToInt32(Eval("AnswerType"))) %>
<% if (iAnswerType == 1) { %>
then all of the radio code here with it's eval statements...
<% } else { %>
then all of the checkbox code here...
<% } %>

It's almost working except that iAnswerType always comes out to be the same number. It doesn't change for each answer correctly. But I know that the Eval("AnswerType") portion is pulling the correct number as I had it just write out on the page as is and it changed correctly by answer. I'm stumped. Any pointers would be much appreciated.
Jul 22 '08 #1
2 1581
bharathreddy
111 100+
hi,

I think it should work. If you are facing conversion problem then why can't you use the string directly instread of converting it to int and using in the if condition.
instead use the string
<%# Eval("AnswerType")=="1" ?
then all of the radio code here with it's eval statements
:
then all of the checkbox code here...
%>


bharath vasireddy
Jul 22 '08 #2
Thanks Bharath! I think you've given me a good direction to pursue. I'm still having a bit of trouble with the syntax though and am getting a "Newline in constant" error. This is the actual code where I'm trying to integrate your suggestion:

<%# Eval("AnswerType")=="1"?<vs:GroupRadioButton ID="selectRadioButton" runat="server" GroupName='<%# Eval("QuestionNum") %>' Checked='<%# RadioShouldBeChecked(Eval("IsChecked")) %>' />:<asp:CheckBox ID="test" runat="server" />%>

I'm sure as a newbie I've mangled it in some way. Is there anything that jumps out at you that may correct it?

thanks again

hi,

I think it should work. If you are facing conversion problem then why can't you use the string directly instread of converting it to int and using in the if condition.
instead use the string
<%# Eval("AnswerType")=="1" ?
then all of the radio code here with it's eval statements
:
then all of the checkbox code here...
%>


bharath vasireddy
Jul 22 '08 #3

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

Similar topics

4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
3
by: Scott | last post by:
Relative newbie here, I'm looking to display the value of radio buttons and check boxes on the page before submission. So far I can do most of it. When "Hat" is checked there are to be no color...
2
by: Thomas R | last post by:
Is is possible? In VS.NET 2003, Binding data to the repeater is easy, but when I try to add an ASP:checkbox to the .aspx page, the designer won't recognize it, hence the code view doesn't allow...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
1
by: Mick | last post by:
Hi, Attempting to display a questions list in my aspx page with the help of a repeater. This repeater displays each question (Label and picture) and each answer in a nested repeater. My...
5
by: Matt Jensen | last post by:
Am I right in saying that you can't have a Radiobutton web control inside a repeater bound to a database datasource and (inline) dynamically set it's ID and text properties from the repeaters rows?...
2
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
3
by: Colin | last post by:
Hello, I can manage quite well in ASP but would like some advice in the best way to achieve dynamic layout in ASP.NET and still keep the page and code separate. Let's say I already have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
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,...

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.