tags:

views:

292

answers:

1

I've got a LinkButton control in a user control like this (Accordion is from the AJAX Control Toolkit):

<cc1:Accordion runat="server">
    <Panes></Panes>
    <HeaderTemplate></HeaderTemplate>
    <ContentTemplate>
        <asp:TextBox Text='<%# Bind("Title") %>' runat="server"></asp:TextBox>
        <asp:LinkButton Text="Update" CommandArgument='<%# Container.DataItem %>' CommandName="ItemUpdate" OnCommand="LinkButton_Command" runat="server"></asp:LinkButton>
    </ContentTemplate>
</cc1:Accordion>

The accordion is bound in Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    Accordion1.DataSource = GetACollection();
    Accordion1.DataBind();
}

But in the command event handler, no matter what I do, the arguments are always strings:

protected void LinkButton_Command(object sender, CommandEventArgs e)
{
      // sender is alway a string (the Text of the clicked button)
      // e is always a string property of the Container.DataItem object
}

The strings are coming from the right objects (the button and the bound DataItem, respectively), but I need the objects themselves (the DataItem particularly).

What's going on?

A: 

Wouldn't that be expected behavior..

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.commandargument.aspx

Property Value Type: System..::.String
An optional argument passed to the
Command event handler along with the
associated CommandName property. The
default value is String..::.Empty.

madcolor
doh! you're right. The debugger made me think I could pass objects, but you're right. The property only accepts strings.
Ben Collins
No worries.. I updated with a better link..
madcolor