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

Last post 11-20-2006 9:59 AM by deathtospam. 2 replies.

Sort Posts:

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

    11-16-2006, 10:10 AM
    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 =
  • Re: <asp:Repeater>, checkbox values and ASP.NET 2.0

    11-16-2006, 10:10 PM
    • Loading...
    • divding
    • Joined on 11-17-2006, 2:47 AM
    • Posts 4

    I saw your reply in the other post as well.

    You can try to use CheckBox control, but you'll probably run into something similar to my problem.

  • Re: &lt;asp:Repeater&gt;, checkbox values and ASP.NET 2.0

    11-20-2006, 9:59 AM
    Answer

    Somebody on Usenet took pity on me and posted a solution to my problem!

           http://tinyurl.com/yj7kaf


    It doesn't demonstrate how to do it entirely from the code-behind page, but it's a legit solution that allows me to recheck the selected items with ViewState disabled, and with a minimum of code or complexity.


     -= DeathToSpam =-
     

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter