<asp:Repeater>, checkbox values and ASP.NET 2.0

G

Guest

A few weeks ago, I created a Classic ASP page that connects to a
machine with SQL Server installed on it, prompts the user to select a
database on that server, then lists all of user-created stored
procedures in that database. The user can select any of those stored
procedures by clicking on checkboxes; after submitting their
selections, a script to delete and then re-create each stored procedure
will be generated. Now I'm trying to do the same thing using ASP.NET.

I wanted to render the checkboxes inside an HTML table column, so I
avoided using the <asp:CheckBoxList> control. Instead, I opted to use
an <asp:Repeater> control with an HTML <input type="checkbox"
runat="server"> tag inside the Repeater's <ItemTemplate> server-side
element. Here's an snippet of my ASPX code:

======================================================
<asp:Repeater runat="server" ID="StoredProcedureCheckboxList"
Visible="false">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="3" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:30px;"><input type="checkbox"
name="SelectedStoredProcedureIds" value="<%#
DataBinder.Eval(Container.DataItem, "StoredProcedureID") %>"
title="[<%# DataBinder.Eval(Container.DataItem, "StoredProcedureID")
%>] <%# DataBinder.Eval(Container.DataItem, "StoredProcedureName")
%>"></td>
<td><%# DataBinder.Eval(Container.DataItem,
"StoredProcedureName") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table><br>
</FooterTemplate>
</asp:Repeater>
======================================================

The above ASPX code works, and I had no problem retrieving the selected
checkbox string values (via the Request.Form collection) after
postback. However, I also wanted all of the checkboxes the user
selected to remain selected after postback. And that's when I realized
that I didn't know how to get a reference (via C# code-behind page) to
the collection of checkboxes inside the <asp:Repeater> control.

I know I could probably use the page's ViewState to do this, but I
wanted to start simple. I've also posted a barebones version of my
project ( http://tinyurl.com/yztohf ), to help illustrate my problem:
the project is comprised of three small files (ASPX, CS & Web.config)
authored in Visual Studio .NET 2005. All you need to do is modify
Web.config so that the [MyDatabase] connection string points to your
database, and it should work just fine. Any advice or tips would be
greatly appreciated... thanks in advance!

-= 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

Members online

No members online now.

Forum statistics

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

Latest Threads

Top