Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
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
  #2 (permalink)  
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,133
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?
  #3 (permalink)  
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.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:11 AM
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



All times are GMT -4. The time now is 06:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.