UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Bind Dropdownlist In Detailsview Insertitemtemplate Error    
 
   
martinshear
post Mar 30 2017, 12:55 AM
Post#1



Posts: 36
Joined: 29-October 02



I am trying to bind a dropdownlist box in Detailsview using SelectedValue='<%# Bind("PersonID") %>' however I get an error Error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context

I removed SelectedValue='<%# Bind("PersonID") %>'
from
<asp:DropDownList ID="DropDownClientEdit" runat="server" DataSourceID="SqlDataClientEdit" DataTextField="AccountName" DataValueField="PersonID" SelectedValue='<%# Bind("PersonID") %>' CssClass="shear-style1" Height="20px">
</asp:DropDownList>

To
<asp:DropDownList ID="DropDownClientEdit" runat="server" DataSourceID="SqlDataClientEdit" DataTextField="AccountName" DataValueField="PersonID" CssClass="shear-style1" Height="20px">
</asp:DropDownList>

and added the following code behind and still cannot get it to work
protected void DetailsVehHire_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
//e.NewValues("PersonID") = DirectCast(DirectCast(sender, DetailsView).FindControl("DropDownClientEdit"), DropDownList).SelectedValue
e.Values["PersonID"] = ((DropDownList)((DetailsView)sender).FindControl("DropDownClientEdit")).SelectedValue;
}

I also tried
protected void DetailsVehHire_DataBound(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)DetailsVehHire.FindControl("DropDownClientEdit");
ddl.Items.Insert(0, new ListItem("Select Client"));
DetailsView dv1 = (DetailsView)DetailsVehHire;
if (dv1.DataItem != null)
{
string strLevelID = ((DataRowView)dv1.DataItem)["PersonID"] as string;
ListItem lm = ddl.Items.FindByValue(strLevelID);
if (lm != null) lm.Selected = true;
}

Any ideas where am going wrong
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    28th June 2017 - 02:09 PM