Dynamically add RadioButtons in Repeater

G

Guest

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...
 
G

Guest

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.DataItem,
"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,"TisUnitType","{0}"))%>

</td>

<td class="tb1px" align="center">
<%#
GenControl(DataBinder.Eval(Container.DataItem,"TisUnitType","{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.DataItem, "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 "";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top