【发布时间】:2010-10-18 15:31:11
【问题描述】:
我在这样的用户控件中有一个 LinkButton 控件(Accordion 来自 AJAX 控件工具包):
<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>
手风琴在Page_Load中绑定:
protected void Page_Load(object sender, EventArgs e)
{
Accordion1.DataSource = GetACollection();
Accordion1.DataBind();
}
但在命令事件处理程序中,无论我做什么,参数始终是字符串:
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
}
字符串来自正确的对象(分别是按钮和绑定的 DataItem),但我需要对象本身(特别是 DataItem)。
发生了什么事?
【问题讨论】:
标签: asp.net