Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2010, 03:30 PM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default ListView EditItemTemplate doesn't bind data in declarative code

I've been working to bind data in a ListView declaratively (with the EditItemTemplate). The page with the code below displays the initial values but refuses to update anything when I click the Update button. Any ideas?

Code:
    <asp:LinqDataSource ID="srcProfile" ContextTypeName="[Data Context]" TableName="[table name]"
        Where="UserID = guid(@UserID)" EnableUpdate="True" runat="server">
        <WhereParameters>
            <asp:SessionParameter Name="UserID" SessionField="UserID" />
        </WhereParameters>
    </asp:LinqDataSource>
    <asp:ListView ID="lsvProfile" DataSourceID="srcProfile" ItemPlaceholderID="itemContainer"
        EditIndex="0" DataKeyNames="UserID" runat="server">
        [snip]
        <EditItemTemplate>
            <asp:UpdatePanel ID="udpEFul" runat="server" Visible="true">
                <ContentTemplate>
                    <div class="profile-content">
                        <cc2:ful ID="fulE" runat="server" />
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
            <tr>
                <td colspan="3">
                    <div class="profile-buttons">
                        <asp:Button ID="btnEUpdate01" runat="server" CommandName="Update" 
                            TabIndex="170" Text="Update" />
                        <asp:Button ID="btnECancel01" runat="server" CommandName="Cancel" 
                            onclick="btnCancel_Click" TabIndex="175" Text="Cancel" />
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="1">
                    <table style="color: #999999;">
<asp:Panel ID="pnlEmail" Visible="true" runat="server">
    <div>
        <tr>
            <td colspan="1">
                <span class="label">
                    <asp:Label ID="lblEmail" Text="E-mail:" runat="server" />
                </span>
            </td>
            <td colspan="1">
                <span class="ctrl">
                    <asp:TextBox ID="Email" CausesValidation="true" EnableViewState="False" Font-Bold="false" Text='<%#Bind("Email")%>'
                        BackColor="#FFFFFF" Enabled="true" TabIndex="50" runat="server" />
                </span>
            </td>
            <td colspan="1">
                <span class="req">
                    <asp:Label ID="lblEmail_Req" Text="*" ForeColor="#FF0000" runat="server" />
                </span>
            </td>
            <td colspan="1">
                <span class="disp">
                    <asp:UpdatePanel ID="udpDisEmail" UpdateMode="Conditional" runat="server">
                        <ContentTemplate>
                            <asp:CheckBox ID="chkEmail" AutoPostBack="true" Checked='<%#Bind("Email_Disp") %>' Enabled="true" TabIndex="500"
                                Text="Display?" TextAlign="left" runat="server" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </span>
            </td>
        </tr>
    </div>
</asp:Panel>
<asp:Panel ID="pnlEmailVal" Visible="true" runat="server">
    <tr>
        <td colspan="4">
            <div class="rfv-container">
                <asp:RequiredFieldValidator ID="rfvEmailRequired" ControlToValidate="Email" Display="Dynamic"
                    ErrorMessage="*E-mail Required" Font-Bold="True" Font-Size="Smaller" SetFocusonerror="true"
                    Text="*E-mail Required" ToolTip="E-mail Address Required" runat="server" />
            </div>
        </td>
    </tr>
    <tr>
        <td colspan="4">
            <div class="rfv-container">
                <asp:RegularExpressionValidator ID="rxvEmail" ControlToValidate="Email" Display="dynamic"
                    ErrorMessage="*Valid e-mail address required" Font-Bold="true" Font-Size="8pt"
                    SetFocusonerror="true" Text="*Valid e-mail address required" ValidationExpression=".*@.*\..*"
                    runat="server" />
            </div>
        </td>
    </tr>
</asp:Panel>
                    </table>
                </td>
            <table class="profile-table-buttons">
                <cc3:pers ID="persE" runat="server" />
                <tr>
                    <td colspan="3">
                        <div style="text-align: center; margin-top: 15px;">
                            <asp:Button ID="btnEUpdate02" runat="server" CommandName="Update" 
                                TabIndex="170" Text="Update" />
                            <asp:Button ID="btnECancel02" runat="server" CommandName="Cancel" 
                                onclick="btnCancel_Click" TabIndex="175" Text="Cancel" />
                        </div>
                    </td>
                </tr>
            </table>
        </EditItemTemplate>
[snip]
    <asp:ListView
 
Old September 9th, 2010, 03:27 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I don't think placing the UpdatePanel inside the EditItemTemplate will work. Try wrapping the entire ListView inside the UpdatePanel.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 16th, 2010, 10:09 PM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2010
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks, Sam. I found that the problem lies in the fact that my bind statements are actually contained in separate user controls (I know, I should have disclosed that fact but I wanted to simplify), and these user controls aren't binding. I know this is true because when I pasted the content of my user controls back into the aspx page, they worked (bound and displayed the data correctly).

In other words, the user control is called thusly from the aspx page:

Code:
<Prf:email ID="EmailE" runat="server" />
The user control is pretty standard stuff but doesn't bind when it's in its separate ascx page:

Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="email.ascx.vb" Inherits="userControls_profile_email" %>
<asp:Panel ID="pnlEmail" Visible="true" runat="server">
    <div class="label">
        <asp:Label ID="lblEmail" Text="E-mail:" runat="server" />
    </div>
    <div class="ctrl">
        <asp:TextBox ID="Email" CausesValidation="true" EnableViewState="False" Font-Bold="false"
            Text='<%#Bind("Email")%>' BackColor="#FFFFFF" Enabled="true" TabIndex="50" runat="server" />
    </div>
    <div class="req">
        <asp:Label ID="lblEmail_Req" Text="*" ForeColor="#FF0000" runat="server" />
    </div>
    <asp:UpdatePanel ID="udpDisEmail" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <div class="disp">
                <asp:CheckBox ID="chkEmail" AutoPostBack="true" Checked='<%#Bind("Email_Disp") %>' 
                    Enabled="true" TabIndex="500" Text="Display?" TextAlign="left" runat="server" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlEmailVal" Visible="true" runat="server">
    <div class="valid-container">
        <asp:RequiredFieldValidator ID="rfvEmailRequired" ControlToValidate="Email" Display="Dynamic"
            ErrorMessage="*E-mail Required" Font-Bold="True" Font-Size="Smaller" SetFocusOnError="true"
            Text="*E-mail Required" ToolTip="E-mail Address Required" runat="server" />
    </div>
    <div class="valid-container">
        <asp:RegularExpressionValidator ID="rxvEmail" ControlToValidate="Email" Display="dynamic"
            ErrorMessage="*Valid e-mail address required" Font-Bold="true" Font-Size="8pt"
            SetFocusOnError="true" Text="*Valid e-mail address required" ValidationExpression=".*@.*\..*"
            runat="server" />
    </div>
</asp:Panel>
Someone in the asp.net forums referred me to the following page but I didn't understand completely how to apply it to my particular case:

http://www.codenewsgroups.net/group/...opic17568.aspx

If someone can give me some extra tips on how to proceed, either with advice on how to implement the tips on that page or any other method, I'd really appreciate it.

Last edited by muybn; September 16th, 2010 at 10:22 PM..




Similar Threads
Thread Thread Starter Forum Replies Last Post
Declarative arguments passing between DetailsViews andremi Classic ASP Basics 1 May 10th, 2007 09:24 PM
Beginner :: Need help to bind the data in GridView kajal SQL Server 2005 1 March 31st, 2007 04:26 PM
How to Bind Data in DataGrid akumarp2p C# 2005 2 December 30th, 2006 12:11 PM
how to bind a data() lsxx Classic ASP Components 4 April 20th, 2005 02:35 AM
How to bind data to a dropdown in a datalist thats broushly ASP.NET 1.0 and 1.1 Basics 1 April 28th, 2004 01:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.