Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 23rd, 2011, 07:49 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Databinding methods such as Eval(), XPath(), and Bind() can only be used in the conte

Hi guys

I've got a development question? I've setup a user control (ascx) on one of my pages for generating a new user account. In my control I have three dropdownlists for the administrator of the system to select from when generating the account. Each dropdownlist is linked to a different sql datasource, i.e. Role, UserType and Service.

The problem I have is at runtime I get "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control". As far as I can see there should be no problem binding the dropdownlist to the sql datasources at runtime but I still receive this error.

Has anyone else experienced the same issue?

Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="NewUser.ascx.vb" Inherits="ExistingUser" %>

<style type="text/css">

    .style1
    {
        width: 900px;
    }
    .InputBox
    {
        width: 300px;
    }
    .Button
    {
        font-family: Tahoma;
        color: #6e6e6e;
        width: 95px;
    }
    .style4
    {
        height: 20px;    
    }
    .style5
    {
        width: 400px;
    }
</style>
<table class="style1" runat="server" id="FormTable">
    <tr>
        <td class="style4">
            Please enter a
            User
            Name</td>
        <td class="style5">
            <asp:TextBox ID="NewUserNameTextBox" ToolTip="Please enter a User Name" runat="server"></asp:TextBox>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style4">
            Please enter a
            Password</td>
        <td class="style5">
            <asp:TextBox ID="NewPasswordTextBox" ToolTip="Please enter a Password" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="NewPasswordTextBox" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter a valid password">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style4">
            Please verify the Password</td>
        <td class="style5">
            <asp:TextBox ID="NewPasswordVerifyTextBox" 
                ToolTip="Please verify the Password" runat="server" ></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="NewPasswordVerifyTextBox" CssClass="ErrorMessage" 
                Display="Dynamic" ErrorMessage="Confirm a valid password">*</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidator2" runat="server" 
                ControlToCompare="NewPasswordTextBox" ControlToValidate="NewPasswordVerifyTextBox" 
                CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Retype the password">*</asp:CompareValidator>
        </td>
    </tr>
    <tr>
        <td class="style4">
            Please enter an
            E-mail Address</td>
        <td class="style5">
            <asp:TextBox ID="NewEmailAddressTextBox" ToolTip="Please enter an Email Address" runat="server"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="NewEmailAddressTextBox" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Enter a valid e-mail address">*</asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                ControlToValidate="NewEmailAddressTextBox" CssClass="ErrorMessage" 
                Display="Dynamic" ErrorMessage="Enter a valid e-mail address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
        </td>
    </tr>
    <tr>
        <td class="style4">
            Please verify an E-mail Address</td>
        <td class="style5">
            <asp:TextBox ID="NewEmailAddressVerifyTextBox" 
                ToolTip="Please verify the Email Address" runat="server" ></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="NewEmailAddressVerifyTextBox" CssClass="ErrorMessage" 
                Display="Dynamic" ErrorMessage="Confirm a valid e-mail address">*</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidator1" runat="server" 
                ControlToCompare="NewPasswordTextBox" ControlToValidate="NewPasswordVerifyTextBox" CssClass="ErrorMessage" Display="Dynamic" 
                ErrorMessage="Retype the e-mail address">*</asp:CompareValidator>
        </td>
    </tr>
    <tr>
        <td class="style4">
            Please select a
            Role Type</td>
        <td class="style5">
            <asp:DropDownList ID="RoleDropDownList" runat="server" 
                DataSourceID="SqlDataSourceRoleNew" DataTextField="RoleType" 
                DataValueField="RoleType" SelectedIndex='<%#Bind("RoleID")%>'>
            </asp:DropDownList>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style4">
            Please select a
            User Type</td>
        <td class="style5">
            <asp:DropDownList ID="UserTypeDropDownList" runat="server" 
                DataSourceID="SqlDataSourceUserTypeNew" DataTextField="UserTypeDescription" 
                DataValueField="UserTypeDescription" 
                SelectedIndex='<%#Bind("UserTypeID")%>'>
            </asp:DropDownList>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style4">
            Please select
            Service Location</td>
        <td class="style5">
            <asp:DropDownList ID="ServiceDropDownList" runat="server" 
                DataSourceID="SqlDataSourceServiceNew" DataTextField="ServiceDescription" 
                DataValueField="ServiceDescription" SelectedIndex='<%#Bind("ServiceID")%>'>
            </asp:DropDownList>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="style4" colspan="3">
            <asp:ValidationSummary ID="ValidationSummary" runat="server" CssClass="ErrorMessage" HeaderText="Please correct the following errors before creating the user account" 
                ShowMessageBox="True" ShowSummary="False" />
        </td>
    </tr>
    </table>
    
    
    <asp:SqlDataSource ID="SqlDataSourceRoleNew" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LiteratureCataloguingConnectionString %>" 
        
    SelectCommand="SELECT DISTINCT RoleType, RoleID FROM Roles ORDER BY RoleType"></asp:SqlDataSource>
    
    <asp:SqlDataSource ID="SqlDataSourceUserTypeNew" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LiteratureCataloguingConnectionString %>" 
        
    SelectCommand="SELECT DISTINCT UserTypeID, UserTypeDescription FROM UserType ORDER BY UserTypeDescription"></asp:SqlDataSource>
    
    <asp:SqlDataSource ID="SqlDataSourceServiceNew" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LiteratureCataloguingConnectionString %>" 
        
    SelectCommand="SELECT DISTINCT ServiceID, ServiceDescription FROM Service ORDER BY ServiceDescription"></asp:SqlDataSource>

<script src="../Scripts/jquery.updnWatermark.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $.updnWatermark.attachAll({ cssClass: 'Watermark' });
    });
</script>
Reply With Quote
  #2 (permalink)  
Old March 9th, 2011, 03:11 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default use Object Data Source

hello
i encountered this problem. when you want to set DataSource or DataSourceID property of some controls that are bind to db, you get an error. this is because of that it is impossible to bind a control to 2 data source. you can do this by binding dropDownList to 3 ObjectDataSource
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
EVAL() andysk C# 2008 aka C# 3.0 1 April 6th, 2011 07:44 AM
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the conte mashype ASP.NET 3.5 Basics 0 May 22nd, 2009 10:10 PM
Name "Eval" is not declared. thuyvncr BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 December 21st, 2006 03:48 AM
Eval??? tsimsha Classic ASP Basics 2 January 17th, 2005 10:02 PM
Databinder.Eval jpfree71 ASP.NET 1.0 and 1.1 Basics 2 August 26th, 2004 11:07 AM



All times are GMT -4. The time now is 05:34 AM.


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