472,127 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

ObjectDataSource UpdateMethod with integer collection


I have a method with the following signature:

public bool UpdateSetAccounts(int[] items) { }

How do I pass a collection of selected values in a ListBox to this
ObjectDataSource UpdateMethod?

I can pass the ListItemCollection in a ControlParameter, e.g.

<asp:ControlParameter ControlID="lbxAssignees" Type="object"
PropertyName="Items" Name="items" />

Not sure how to deal with it in the Updating event, e.g.

protected void odsSetAccounts_Updating(object sender,
ObjectDataSourceMethodEventArgs e)
ListItemCollection items = (ListItemCollection)e.InputParameters[0];
// what happens next?

I must be missing something obvious in the documentation. Handling multiple
selected values in ListBoxes, CheckboxLists, etc must be fairly standard. Is
there a recommended way of using these with ObjectDataSource controls?

Oct 17 '06 #1
2 3840
Hello Andrew,

For your scenario, your data access class's update method will take a int[]
input parameter and you use it in ObjectDatasoruce, and the parameter
source is a ListBox(configuer as multi-select ), I think you need to take
care of the following things:

1. You should not directly associate the ListBox.Items to
ObjectDataSource's update parameter, because they're unmatched on type(one
is ListItemCollection, the other is int[])

2. You're right that you need to manually pass in the paramter through
ObjectDataSource's Updating event

Here is a simple example demonstrate pass parameter from ListBox's selected
items into my custom object's update method through objectDatasource:

=========custom class=========
public class DataAccessObject
public DataAccessObject()


public int[] GetItems()

return new int[] { 1,2,3,4,5,6,7,8,9};
public void UpdateItems(int[] items)

+ items.Length);
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetItems" TypeName="DataAccessObject"
UpdateMethod="UpdateItems" OnUpdating="ObjectDataSource1_Updating">
<asp:Parameter Name="items" />
<asp:ListBox ID="ListBox1" runat="server"
DataSourceID="ObjectDataSource1" Height="286px" SelectionMode="multiple"
Width="167px"></asp:ListBox><br />
<asp:Button ID="btnUpdate" runat="server" Text="Update"
OnClick="btnUpdate_Click" /></div>

=========code behind==========
public partial class dataaccess_ObjArrayDS : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void btnUpdate_Click(object sender, EventArgs e)

protected void ObjectDataSource1_Updating(object sender,
ObjectDataSourceMethodEventArgs e)
ArrayList list = new ArrayList();
foreach (ListItem item in ListBox1.Items)
if (item.Selected == true)

int[] items = (int[])list.ToArray(typeof(int));

e.InputParameters["items"] = items;

Actually, for such scenario, it's more straightforward that we directly
call the custom class's method instead of ObjectDataSource.

Hope this helps.


Steven Cheng

Microsoft MSDN Online Support Lead


Get notification to my posts through email? Please refer to

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


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

Oct 18 '06 #2
Hi Steven

Thanks for the information. That's very helpful.

Oct 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by mthomason | last post: by
reply views Thread by avital | last post: by
4 posts views Thread by tim.cavins | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.