DataView Error on Update With DropDownList

A

AG

Hi,
ASP.NET 2.0 web app

I have a GridView utilizing template columns and bound to an
objectdatasource.
In the edit template of one column there is a dropdownlist bound to another
objectdatasource.
The dropdownlist displays the appropriate values when entering edit mode.
However when I try to update, I receive the following error.

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

Here is the edititemtemplate
<EditItemTemplate>
<asp:DropDownList id="ddlNetDataType" runat="server" EnableViewState="False"
DataSourceID="odsNetDataTypes" SelectedValue='<%# Bind("NetDataType") %>'
DataTextField="NetDataType" DataValueField="NetDataType"></asp:DropDownList>
</EditItemTemplate>



Can anyone offer a fix?

TIA

AG
Email: discuss at adhdata dot com
 
W

Walter Wang [MSFT]

Hi AG,

This is a known issue. The fix is to turn on ViewState of the DropDownList:

#ASP.NET Forums - Problem of binding SelectedValue to DropDownList in
templated DetailsView
http://forums.asp.net/1004263/ShowPost.aspx
This is a problem that we're aware of. The issue occurs because your
dropdownlists have viewstate turned off but your detailsview has it
enabled. You can either enable viewstate for your dropdownlists or disable
it for your detailsview, and the error should go away.



Let me know if this helps. Thanks.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

Walter,

Thanks for the response.

It probably makes no difference, but I am using a gridview, not a
detailsview. Sorry for the error in the subject of my post.
Turning on viewstate for the dropdownlist does prevent the error.
I would prefer to have it turned off.
I left viewstate turned on for the gridview because I am using paging and
thought that viewstate must be turned on in order to utilize paging. Is this
correct?

Are there plans to correct this issue?
 
W

Walter Wang [MSFT]

Hi AG,

Regarding this case, apparently GridView and DetailsView all have the issue
as described in the forum post; thus for current moment using the
workaround of turning on ViewState of the DropDownList should be the only
way to get it working. Since this DropDownList only sends its ViewState
back to client browser when you're actually editing the row, it only
affects the page size in this case; it should not impact the page size when
user's viewing the GridView.

I'll go and check if there's any plan to fix it. Thank you for your
patience and understanding.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

Thanks Walter.

I would still like to know if I must keep viewstate turned on for the
gridview.
As you stated, if I turn off viewstate for the gridview, then I can also
turn it off for the dropdownlist.
I do understand that the dropdownlist viewstate is only posted back when in
edit mode, but my actual case is that I am using a custom control that
inherits the gridview and provides an insert row to add a record. That row
also contains the same dropdownlist as my edit row, so viewstate is always a
factor.

So, the question at hand is:

If I turn off viewstate for the gridview, will I lose any functionality, or
will it simply need to be databound in each postback?
 
W

Walter Wang [MSFT]

Hi AG,

Turning off viewstate for the GridView will work if it's rebound in each
postback. However, there're some known issues which you should be aware of:

#Scott on Writing
http://scottonwriting.net/sowblog/posts/10054.aspx
WARNING: Concurrency Issue with ASP.NET 2.0 GridViews/DetailsView/FormViews
that Support Editing and/or Deleting and Whose View State is Disabled


Also, I've consulted with product team on the issue, they're actually aware
of this issue (as noted in the forum post I referenced in my first reply);
however, since it's a rather difficult one, it just takes more time to fix
it and unfortunately we cannot tell exactly when will it be fixed. We're
sorry for the inconvenience and appreciate for your understanding.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

Thanks Walter,

For now, I will be leaving viewstate on for the gridview and dropdown.
I tried turning off viewstate for both and saw another problem.
The datasource for the gridview is a objectdatasource representating a
custom class that returns a dataview .
When I apply a filter to the objectdatasource and try to edit a row in the
gridview, the wrong row is edited.
A similar problem to the one you referenced. It seems that the gridview
references the full data source, and not just the filtered data when
viewstate is turned off.
 
W

Walter Wang [MSFT]

Hi AG,

Thank you very much for your update.

I would also suggest turning on viewstate for both the GridView and
DropDownList at current moment.

Again, you're welcome to submit your feedback at
http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220 which
is monitored by our product team directly.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top