ASP.NET v2.0 and Repeater controls

G

Guest

I've written some code (C# / ASP.NET on .NET v2.0) that allows me to
list all stored procedures in a SQL Server database, along with with
their associated CREATE PROCEDURE statements. Here's an excerpt from
that code:

============================================
<asp:Repeater runat="server" ID="StoredProcedureCheckboxList">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr style="height:0px;">
<td style="width:30px;" nowrap></td>
<td></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><input type="checkbox" name="SelectedStoredProcedureIds"
value="<%# DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>"></td>
<td><a href="javascript:void(0);"
onclick="document.getElementById('tr<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>').style.display = ((document.getElementById('tr<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>').style.display == '')?('none'):(''));"><%#
DataBinder.Eval(Container.DataItem, "StoredProcedureName") %></a></td>
</tr>
<tr id="tr<%# DataBinder.Eval(Container.DataItem,
"StoredProcedureID") %>" style="display:none;">
<td colspan="2"><pre class="code"><%#
DataBinder.Eval(Container.DataItem, "StoredProcedureTextChunk")
%></pre></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table><br>
</FooterTemplate>
</asp:Repeater>
============================================


What I need to do is get a reference (via my C# code-behind page) to
the collection of checkboxes generated by this control, so I can
loop/iterate through them. I tried adding [ runat="server" ] to the
<input type="checkbox"> tag, but that gave me an compiler error message
("The server tag is not well-formed"). I'm probably missing something
obvious (I'm an ASP.NET newbie)... any suggestions or comments would be
greatly appreciated!


-= Tek Boy =-
 
E

Eliyahu Goldin

You don't get a collection of the checkboxes. Rather you get a collection of
the repeater items. Add runat="server" and the id attributes to the
checkbox. Having done this, you will be able to locate the checkbox in the
item with the FindControl method.

Your error was likely caused by misplacing the runat attribute. Make sure
you put it in a right place, outside of any other attributes.
 
G

Guest

Eliyahu --

I don't believe I misplaced the [ runat="server" ] property assignment
-- I think there's some other problem. Without it everything compiles,
but when I make the changes you suggested, I still get the same error:

============================================
....
<td><input type="checkbox" runat="server" id="Something"
name="SelectedStoredProcedureIds" value="<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID") %>"></td>
....
============================================


Also, I don't believe assigning an ID property value to the <input
type="checkbox"> tag inside <ItemTemplate> will work, as each rendered
checkbox with then have the same ID value (and therefore not be
unique). But I can't check to make sure without resolve the first
problem (making the checkboxes available to my C# code-behind).


-= Tek Boy =-

Eliyahu said:
You don't get a collection of the checkboxes. Rather you get a collection of
the repeater items. Add runat="server" and the id attributes to the
checkbox. Having done this, you will be able to locate the checkbox in the
item with the FindControl method.

Your error was likely caused by misplacing the runat attribute. Make sure
you put it in a right place, outside of any other attributes.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I've written some code (C# / ASP.NET on .NET v2.0) that allows me to
list all stored procedures in a SQL Server database, along with with
their associated CREATE PROCEDURE statements. Here's an excerpt from
that code:

============================================
<asp:Repeater runat="server" ID="StoredProcedureCheckboxList">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr style="height:0px;">
<td style="width:30px;" nowrap></td>
<td></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><input type="checkbox" name="SelectedStoredProcedureIds"
value="<%# DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>"></td>
<td><a href="javascript:void(0);"
onclick="document.getElementById('tr<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>').style.display = ((document.getElementById('tr<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>').style.display == '')?('none'):(''));"><%#
DataBinder.Eval(Container.DataItem, "StoredProcedureName") %></a></td>
</tr>
<tr id="tr<%# DataBinder.Eval(Container.DataItem,
"StoredProcedureID") %>" style="display:none;">
<td colspan="2"><pre class="code"><%#
DataBinder.Eval(Container.DataItem, "StoredProcedureTextChunk")
%></pre></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table><br>
</FooterTemplate>
</asp:Repeater>
============================================


What I need to do is get a reference (via my C# code-behind page) to
the collection of checkboxes generated by this control, so I can
loop/iterate through them. I tried adding [ runat="server" ] to the
<input type="checkbox"> tag, but that gave me an compiler error message
("The server tag is not well-formed"). I'm probably missing something
obvious (I'm an ASP.NET newbie)... any suggestions or comments would be
greatly appreciated!


-= Tek Boy =-
 
E

Eliyahu Goldin

Odd. The <input ... > looks ok to me except it is supposed to end with a
"/>".

The ID property will work since the FindControl method expects this sort of
id as opposed to the ClientId sent to the browser.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Eliyahu --

I don't believe I misplaced the [ runat="server" ] property assignment
-- I think there's some other problem. Without it everything compiles,
but when I make the changes you suggested, I still get the same error:

============================================
...
<td><input type="checkbox" runat="server" id="Something"
name="SelectedStoredProcedureIds" value="<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID") %>"></td>
...
============================================


Also, I don't believe assigning an ID property value to the <input
type="checkbox"> tag inside <ItemTemplate> will work, as each rendered
checkbox with then have the same ID value (and therefore not be
unique). But I can't check to make sure without resolve the first
problem (making the checkboxes available to my C# code-behind).


-= Tek Boy =-

Eliyahu said:
You don't get a collection of the checkboxes. Rather you get a collection
of
the repeater items. Add runat="server" and the id attributes to the
checkbox. Having done this, you will be able to locate the checkbox in
the
item with the FindControl method.

Your error was likely caused by misplacing the runat attribute. Make sure
you put it in a right place, outside of any other attributes.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I've written some code (C# / ASP.NET on .NET v2.0) that allows me to
list all stored procedures in a SQL Server database, along with with
their associated CREATE PROCEDURE statements. Here's an excerpt from
that code:

============================================
<asp:Repeater runat="server" ID="StoredProcedureCheckboxList">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr style="height:0px;">
<td style="width:30px;" nowrap></td>
<td></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><input type="checkbox" name="SelectedStoredProcedureIds"
value="<%# DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>"></td>
<td><a href="javascript:void(0);"
onclick="document.getElementById('tr<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>').style.display = ((document.getElementById('tr<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>').style.display == '')?('none'):(''));"><%#
DataBinder.Eval(Container.DataItem, "StoredProcedureName") %></a></td>
</tr>
<tr id="tr<%# DataBinder.Eval(Container.DataItem,
"StoredProcedureID") %>" style="display:none;">
<td colspan="2"><pre class="code"><%#
DataBinder.Eval(Container.DataItem, "StoredProcedureTextChunk")
%></pre></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table><br>
</FooterTemplate>
</asp:Repeater>
============================================


What I need to do is get a reference (via my C# code-behind page) to
the collection of checkboxes generated by this control, so I can
loop/iterate through them. I tried adding [ runat="server" ] to the
<input type="checkbox"> tag, but that gave me an compiler error message
("The server tag is not well-formed"). I'm probably missing something
obvious (I'm an ASP.NET newbie)... any suggestions or comments would be
greatly appreciated!


-= Tek Boy =-
 

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

Top