473,324 Members | 2,268 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,324 software developers and data experts.

Dynamically add RadioButtons in Repeater

Hi everyone,

Could you please help me with this?
I need to create a table in which resultdata from a sql server table can be
shown and/or edited by using controls, for instance the radiobutton.

To do this I use an Repeater and another repeater nested in it.
All works well when I create the control radiobutton as a static in the aspx
page.

The problem is that there are different kinds of data in the database and
for some data there will be the need to show a yes/no selection with 2
radiobuttons, as for another item it should be a textbox control..

I tried to automate the generation by calling a function in the code behind
page that will return the "<ASP:RadioButton....... />" string, but then it is
a literal text in the generated page instead of a radiobutton...

Can anyone tell me if, and if so, how it's possible to create these controls
on the fly?

Thank you,

Kind regards,

Chris.

PS: I've added the code to clarify what I've done. If you know where I did
something wrong, and have a solution, please help me...

Nov 19 '05 #1
1 1801
Hi again,

oops... I forgot to paste the code...

---------------------------------8<--------------------------------------
<ASP:Repeater ID="RptTestResultData" runat="server">
<HeaderTemplate>
<TABLE id="mainTable" cellSpacing="0" class="border1px" >
<TR valign="top">
<TH width="220" rowSpan="2" class="lrb1px" >Test</TH>
<TH width="100" colSpan="2" height="19" class="lrb1px"
style="border-bottom:solid 1px #C3C3C3;">Acceptable</TH>
<TH width="170" rowSpan="2" class="lrb1px" >Testcriteria </TH>
<TH width="90" rowSpan="2" class="lrb1px" >Unit </TH>
<TH width="90" rowSpan="2" class="lrb1px" >Value</TH><TH width="10"
colSpan="5" rowSpan="2"> </TH>
</TR>
<TR style="font-size:10pt;">
<TH class="lrb1px" >Yes</TH><TH class="lrb1px">No</TH>
</TR>
</HeaderTemplate>

<ItemTemplate>
<TR>
<th align="left" colspan="11" class="tb1px"
style="font-size:10pt;"><%#DataBinder.Eval(Container.DataItem, "TestName")%></th>
</TR>

<ASP:Repeater ID="RtpTestResultDataDetail" runat="server"
Datasource='<%# getTestDataSource(DataBinder.Eval(Container.DataIt em,
"TestName","{0}") )%>'>

<ItemTemplate>
<TR >
<td class="tb1px"
style="padding-left:2em;"><%#DataBinder.Eval(Container.DataItem," TisNameEnglish")%></td>
<td class="tb1px" align="center">
<%#
GenControl(DataBinder.Eval(Container.DataItem,"Tis UnitType","{0}"))%>

</td>

<td class="tb1px" align="center">
<%#
GenControl(DataBinder.Eval(Container.DataItem,"Tis UnitType","{0}"))%>

</td>
<TD class="tb1px"> </TD>
<TD class="tb1px"> </TD>
<TD class="tb1px"> </TD>
<TD class="tb1px"> </TD>
<TD class="tb1px"><IMG height="16" alt="Read Report"
src="<%=AppContext%>/resources/images/report.png" width="16"
style="cursor:hand;"></TD>
<TD class="tb1px"><IMG height="16" alt="Enter testresult"
src="<%=AppContext%>/resources/images/edit16x16.gif" width="16"
style="cursor:hand;"></TD>
<TD class="tb1px"><IMG height="16" alt="Add Test Comments"
src="<%=AppContext%>/resources/images/author-icon.PNG" width="16"
style="cursor:hand;"></TD>
</tr>
</ItemTemplate>
</ASP:Repeater>

</ItemTemplate>
<AlternatingItemTemplate>
<TR bgcolor="#fafafa">
<th align="left" colspan="11" class="tb1px"
style="font-size:10pt;"><%#DataBinder.Eval(Container.DataItem, "TestName")%></th>
</TR>

<ASP:Repeater ID="Repeater1" runat="server" Datasource='<%#
getTestDataSource(DataBinder.Eval(Container.DataIt em, "TestName","{0}") )%>'>

<ItemTemplate>
<TR bgcolor="#fafafa">
<td class="tb1px"
style="padding-left:2em;"><%#DataBinder.Eval(Container.DataItem," TisNameEnglish")%></td>
<td class="tb1px" align="center">
<%# DataBinder.Eval(Container.DataItem,"TisUnitType")% >

</td>

<td class="tb1px" align="center">
<%# DataBinder.Eval(Container.DataItem,"TisUnitType")% >

</td>
<TD class="tb1px"> </TD>
<TD class="tb1px"> </TD>
<TD class="tb1px"> </TD>
<TD class="tb1px"> </TD>
<TD class="tb1px"><IMG height="16" alt="Read Report"
src="<%=AppContext%>/resources/images/report.png" width="16"
style="cursor:hand;"></TD>
<TD class="tb1px"><IMG height="16" alt="Enter testresult"
src="<%=AppContext%>/resources/images/edit16x16.gif" width="16"
style="cursor:hand;"></TD>
<TD class="tb1px"><IMG height="16" alt="Add Test Comments"
src="<%=AppContext%>/resources/images/author-icon.PNG" width="16"
style="cursor:hand;"></TD>
</tr>
</ItemTemplate>
</ASP:Repeater>

</AlternatingItemTemplate>

<FooterTemplate>
</TABLE>
</FooterTemplate>

</ASP:Repeater>

Code behind:
-------------------------
protected string GenControl(string s)
{
if (s.IndexOf("Acceptable") != -1)
return "<ASP:RadioButton ID=\"rb\" runat=\"server\"/>";
else
return "";
}


"Christiaan Nieuwlaat" wrote:
Hi everyone,

Could you please help me with this?
I need to create a table in which resultdata from a sql server table can be
shown and/or edited by using controls, for instance the radiobutton.

To do this I use an Repeater and another repeater nested in it.
All works well when I create the control radiobutton as a static in the aspx
page.

The problem is that there are different kinds of data in the database and
for some data there will be the need to show a yes/no selection with 2
radiobuttons, as for another item it should be a textbox control..

I tried to automate the generation by calling a function in the code behind
page that will return the "<ASP:RadioButton....... />" string, but then it is
a literal text in the generated page instead of a radiobutton...

Can anyone tell me if, and if so, how it's possible to create these controls
on the fly?

Thank you,

Kind regards,

Chris.

PS: I've added the code to clarify what I've done. If you know where I did
something wrong, and have a solution, please help me...

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jerad Rose | last post by:
I searched for a while trying to find the answer to this, but to no avail. I am trying to find the best way (or any way) to dynamically show and hide groups of TR's. For example, I have a...
0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like this in the aspx:
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
3
by: Nathan Sokalski | last post by:
I am using the AddHandler statement to add a CheckedChanged event handler to a series of RadioButtons that I create in a loop. However, the handler is not being called for a reason I cannot...
4
by: Terry Holland | last post by:
I am a vb6 programmer just moving over to vb.net. I have an form onto which I have dynamically added a number of panels. I have dynamically added a label and three RadioButtons to each of these...
1
by: Sachin | last post by:
Hi All, I am using Repeater. I am using RadioButton in ItemTemplate as I want to allow the user to select only one row. I have set the GroupName for the RadioButton. However, RadioButton...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
2
by: John Haycock | last post by:
Hi All I have a user control that uses a repeater to build a list of menu links: <itemtemplate> <li> <a href='news.aspx?newsID=<%# DataBinder.Eval(Container.DataItem,"newsID") %>'> <%#...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.