<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Bhat:</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times,
serif">Thanks for your reply and assistance. I think I'm doing everything you have described but I must not be binding the user control correctly. Correct me if I'm wrong but the user control can only be bound to one field? The user control created has two
fields, city and country?</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Is there a way to bind both? My normal binding for
each would be <%# bind("country") %> <%# bind("city") %></div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">In my webform, I'm
using two fields, Contractor and JobTitle. The various contractors can have several to no child job titles. The same type of parent, child relationship as country and city.</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Here is the code I'm using...</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times
new roman, new york, times, serif">This is the user control.... DisplayJobTitle.ascx </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
This is the user control code behind page.... DisplayJobTitle ascx.cs </div>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DisplayJobTitle : System.Web.UI.UserControl
{
public string contractor
{
get
{
return ddl_Contractors.SelectedValue.ToString();
}
set
{
ddl_Contractors.SelectedValue = value;
}
}
public string jobTitle
{
get
{
return ddl_JobTitles.SelectedValue.ToString();
}
set
{
ddl_JobTitles.SelectedValue = value;
}
}
}
This is formview within an edititemtemplate on my webform that is trying to do the cascadding dropdown and be bound....Staff_Edit.aspx</div>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div>
<div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
I get this Error:
InvalidCastException was unhandled by user code. Specified cast is not valid</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times
new roman, new york, times, serif">ERROR is from this line.. <uc1:DisplayJobTitle ID="DisplayJobTitle1" runat="server" Visible='<%# Bind("contractorID") %>' />.. the usercontrol in the webform</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman,
new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">I would assume it's because the binding isn't working...?</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div>
JimAmigo
Member
581 Points
267 Posts
Re: Error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the contex...
Dec 28, 2006 02:21 PM|LINK
<%@ Control Language="C#" ClassName="JobTitles" AutoEventWireup="true" CodeFile="DisplayJobTitle.ascx.cs" Inherits="DisplayJobTitle" %> <asp:DropDownList ID="ddl_Contractors" runat="server" DataSourceID="ods_Contractors" DataTextField="ShortDescription" DataValueField="ContractorID" AutoPostBack="True"> </asp:DropDownList> / <asp:DropDownList ID="ddl_JobTitles" runat="server" DataSourceID="ods_JobTitles" DataTextField="JobTitle" DataValueField="JobTitleID"> </asp:DropDownList><asp:ObjectDataSource ID="ods_JobTitles" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetJobTitlesByContractorID" TypeName="BMSDataSetTableAdapters.JobTitlesTableAdapter"> <SelectParameters> <asp:ControlParameter ControlID="ddl_Contractors" Name="contractorID" PropertyName="SelectedValue" Type="Decimal" /> </SelectParameters> </asp:ObjectDataSource> <asp:ObjectDataSource ID="ods_Contractors" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetContractors" TypeName="BMSDataSetTableAdapters.ContractorsTableAdapter"> </asp:ObjectDataSource>This is the user control code behind page.... DisplayJobTitle ascx.cs </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
This is formview within an edititemtemplate on my webform that is trying to do the cascadding dropdown and be bound....Staff_Edit.aspx</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> I get this Error: InvalidCastException was unhandled by user code. Specified cast is not valid</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">ERROR is from this line.. <uc1:DisplayJobTitle ID="DisplayJobTitle1" runat="server" Visible='<%# Bind("contractorID") %>' />.. the usercontrol in the webform</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">I would assume it's because the binding isn't working...?</div> <div style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </div>