LinkBut​​ton命令事件处理程序args始终为字符串 [英] LinkButton Command event handler args always strings

查看:62
本文介绍了LinkBut​​ton命令事件处理程序args始终为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这样的用户控件中有一个LinkBut​​ton控件(Accordion来自AJAX Control Toolkit):

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>

手风琴绑定在Page_Load中:

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
}

字符串来自正确的对象(分别是按钮和绑定的DataItem),但是我需要对象本身(特别是DataItem).

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

这是怎么回事?

推荐答案

那不是预期的行为.

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

属性值类型:系统.. ::.String
传递给
的可选参数命令事件处理程序以及
关联的CommandName属性.
默认值为String .. ::.Empty.

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.

这篇关于LinkBut​​ton命令事件处理程序args始终为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆