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()
{
HttpContext.Current.Response.Write("<br/>DataAccessObject.GetItems....");
return new int[] { 1,2,3,4,5,6,7,8,9};
}
public void UpdateItems(int[] items)
{
HttpContext.Current.Response.Write("<br/>DataAccessObject.UpdateItems...."
+ items.Length);
}
}
============================
===========aspx==============
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetItems" TypeName="DataAccessObject"
UpdateMethod="UpdateItems" OnUpdating="ObjectDataSource1_Updating">
<UpdateParameters>
<asp:Parameter Name="items" />
</UpdateParameters>
</asp:ObjectDataSource>
<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>
</form>
==============================
=========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)
{
ObjectDataSource1.Update();
}
protected void ObjectDataSource1_Updating(object sender,
ObjectDataSourceMethodEventArgs e)
{
ArrayList list = new ArrayList();
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected == true)
{
list.Add(int.Parse(item.Value));
}
}
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.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.