Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Databinding problem

Reply
Thread Tools

Databinding problem

 
 
David C
Guest
Posts: n/a
 
      05-27-2008
I have a drop down list control where I set AppendDataBound to true and
added a list item of '<< add new>>' with a value of -1 to use for adding
items to the list during data entry. When the user selects the '<< add new
>>' option it runs a Javascript function to get the name of the new item.

The new name is stored in a hidden TextBox and in the Load event I use it to
add the record to the lookup table. Below is the block of code in the Load
event of the FormView.

Dim row As FormViewRow = fvTrademark.Row
Dim varControl
Dim lngNewID As Long = 0
Dim lngTradeID As Long = fvTrademark.DataKey.Value

varControl = row.FindControl("ddlAgentID")
If varControl.SelectedValue = -1 Then
'Run class function to create new record in
tlkpAgent and return ID
lngNewID =
DBClass.CreateNewtlkpAgent(txtNewText.Text, lngTradeID, False)
'set dropdownlist selectedvalue to new agentid
varControl.SelectedValue = lngNewID.ToString
txtNewText.Text = ""
Exit Select
End If

The DBClass function creates a new record in the lookup table (which is used
as the DataSource for the drop down list (ddlAgentID). The error occurs
trying to set the SelectedValue of the control. The error is below:

'ddlAgentID' has a SelectedValue which is invalid because it does not exist
in the list of items.
David



 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-28-2008
SelectedValue property is intented for selecting an existing ddl item with
matching value. It can't be used for modifying items. You need to use
SelectedItem.Value.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"David C" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have a drop down list control where I set AppendDataBound to true and
>added a list item of '<< add new>>' with a value of -1 to use for adding
>items to the list during data entry. When the user selects the '<< add new
> >>' option it runs a Javascript function to get the name of the new item.

> The new name is stored in a hidden TextBox and in the Load event I use it
> to add the record to the lookup table. Below is the block of code in the
> Load event of the FormView.
>
> Dim row As FormViewRow = fvTrademark.Row
> Dim varControl
> Dim lngNewID As Long = 0
> Dim lngTradeID As Long = fvTrademark.DataKey.Value
>
> varControl = row.FindControl("ddlAgentID")
> If varControl.SelectedValue = -1 Then
> 'Run class function to create new record in
> tlkpAgent and return ID
> lngNewID =
> DBClass.CreateNewtlkpAgent(txtNewText.Text, lngTradeID, False)
> 'set dropdownlist selectedvalue to new agentid
> varControl.SelectedValue = lngNewID.ToString
> txtNewText.Text = ""
> Exit Select
> End If
>
> The DBClass function creates a new record in the lookup table (which is
> used as the DataSource for the drop down list (ddlAgentID). The error
> occurs trying to set the SelectedValue of the control. The error is
> below:
>
> 'ddlAgentID' has a SelectedValue which is invalid because it does not
> exist in the list of items.
> David
>
>
>



 
Reply With Quote
 
 
 
 
David C
Guest
Posts: n/a
 
      05-28-2008
That worked, but the new text did not show up in the dropdown list. It
still shows <<new>> instead of the value it should. When I try to use a
DataBind() on the control I get an error "Databinding methods such as
Eval(), XPath(), and Bind() can only be used in the context of a databound
control."

How do I avoid this error so the new text value is displayed?

David
"Eliyahu Goldin" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> SelectedValue property is intented for selecting an existing ddl item with
> matching value. It can't be used for modifying items. You need to use
> SelectedItem.Value.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "David C" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>>I have a drop down list control where I set AppendDataBound to true and
>>added a list item of '<< add new>>' with a value of -1 to use for adding
>>items to the list during data entry. When the user selects the '<< add
>>new
>> >>' option it runs a Javascript function to get the name of the new item.

>> The new name is stored in a hidden TextBox and in the Load event I use it
>> to add the record to the lookup table. Below is the block of code in the
>> Load event of the FormView.
>>
>> Dim row As FormViewRow = fvTrademark.Row
>> Dim varControl
>> Dim lngNewID As Long = 0
>> Dim lngTradeID As Long = fvTrademark.DataKey.Value
>>
>> varControl = row.FindControl("ddlAgentID")
>> If varControl.SelectedValue = -1 Then
>> 'Run class function to create new record in
>> tlkpAgent and return ID
>> lngNewID =
>> DBClass.CreateNewtlkpAgent(txtNewText.Text, lngTradeID, False)
>> 'set dropdownlist selectedvalue to new agentid
>> varControl.SelectedValue = lngNewID.ToString
>> txtNewText.Text = ""
>> Exit Select
>> End If
>>
>> The DBClass function creates a new record in the lookup table (which is
>> used as the DataSource for the drop down list (ddlAgentID). The error
>> occurs trying to set the SelectedValue of the control. The error is
>> below:
>>
>> 'ddlAgentID' has a SelectedValue which is invalid because it does not
>> exist in the list of items.
>> David
>>
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM
RadioButtonList Databinding problem. Arun K ASP .Net 0 12-29-2003 06:40 PM
Re: Problem with DataBinding and CheckBoxList John Saunders ASP .Net 1 08-11-2003 04:15 PM



Advertisments