C# 使用主键由多列组成的中继器时如何处理按钮单击
当ASP.NET中继器项所基于的记录由跨越多列的主键标识时,我需要有关如何处理该项中的按钮单击的帮助 背景: 我所说的页面从数据库中获取C# 使用主键由多列组成的中继器时如何处理按钮单击,c#,asp.net,repeater,C#,Asp.net,Repeater,当ASP.NET中继器项所基于的记录由跨越多列的主键标识时,我需要有关如何处理该项中的按钮单击的帮助 背景: 我所说的页面从数据库中获取投诉,这是一个具有某些属性的对象,并向用户显示其属性 此属性之一是升级,它是一个系统.Collections.Generic.List对象 升级对象只是以下SQL表的代码内表示: create table [escalations] ( [complaint_id] int not null, [escalation_group_id] varc
投诉
,这是一个具有某些属性的对象,并向用户显示其属性
此属性之一是升级
,它是一个系统.Collections.Generic.List
对象
升级
对象只是以下SQL表的代码内表示:
create table [escalations]
(
[complaint_id] int not null,
[escalation_group_id] varchar (50) not null
[escalation_date] datetime not null,
[escalation_text] text not null,
[response_date] datetime null,
[response_text] text null,
constraint [pk_escalations] primary key ([complaint_id], [escalation_date]),
constraint [fk_complaints] foreign key ([complaint_id]) references [complaints].([complaint_id]),
constraint [fk_escalation_groups] foreign key ([escalation_group_id]) references [escalation_groups].([escalation_group_id])
)
要显示升级列表,我选择使用System.Web.UI.WebControl.Repeater
,因为我需要一个复杂的布局,所以我使用了以下代码(这是实际代码的精简版本,以提高可读性,例如“回复此投诉”零件放置在模式弹出窗口中,存在验证器等):
获取投诉id
不是什么大问题,我可以将其保存在视图状态
中,因为每次上报
都是一样的
如果send\u response
按钮上的CommandArgument
是由构建在单个列上的主键标识的,那么我可以在send\u response
按钮上指定一个CommandArgument
,但是由于主键是由投诉id
和升级日期
列构成的,因此无法执行此操作
我甚至找到了一些解决方案,涉及将字段绑定到控件,如System.Web.UI.WebControls.Label
或System.Web.UI.WebControls.Literal
,但由于我需要传递的字段是DateTime
,我不知道如何处理它
问题:
在SendResponse
方法中,可以识别正确的上报
?如果是,我怎么做?如果这不可行,如何更改显示数据的方式
如果有人渴望阅读真正的源代码,这里是,这里是,但我必须警告你:自定义类和属性,方法名称等等都是意大利语
提前感谢您,Andrea。您可以使用按钮的命令事件和您描述的CommandArgument属性,但是在升级对象上创建一个只读属性,该属性返回一些联合主键的连接。将此属性绑定到按钮的CommandArgument 如果不能或不想创建只读属性,可以在代码中编写一个简单的方法来构造连接,并从Eval方法调用它,例如
<asp:Button ...
CommandArgument='<%# ConcatenatePrimaryKeys(Eval("complaint_id"), Eval("escalation_date")) %>'
runat="server" />
protected void SendResponse(Object sender, EventArgs e)
{
// ?!?!
}
<asp:Button ...
CommandArgument='<%# ConcatenatePrimaryKeys(Eval("complaint_id"), Eval("escalation_date")) %>'
runat="server" />