我有一个转发器,可以从复选框列表中的选定项目创建按钮。复选框列表是项目代码列表。
按钮显示正确,并将项目代码作为文本。这样可行。
单击时,按钮应使用按钮的项代码调用方法来调用将数据填充到页面的方法,但这不会发生。我相信按钮传递的是空值。
如何点击转发器按钮以传递正确的值?该方法适用于常规文本框,但我无法使用转发器按钮。
ASPX
` <div style="width: 98%; overflow-x: scroll;">
<asp:Repeater ID="rptItemButtons"
runat="server">
<ItemTemplate>
<asp:Button ID="btnItemButton"
runat="server"
Text='<%# Container.DataItem.ToString() %>'
CommandArgument='<%# Container.DataItem.ToString() %>'
CommandName="repeater_ItemCommand"
/>
</ItemTemplate>
</asp:Repeater>
</div>`
C#
public void repeater_ItemCommand(object sender, CommandEventArgs e)
{
SaveUserInputsAction();
SaveDataAction();
lblTestMessage.Text = e.CommandArgument.ToString();
GetItemDetails(e.CommandArgument.ToString()); GetCostFactors(e.CommandArgument.ToString());
}
答案 0 :(得分:1)
尝试设置OnItemCommand
的{{1}}属性:
ASPX:
Repeater
代码隐藏:
<asp:Repeater ID="rptItemButtons" OnItemCommand="Repeater_ItemCommand" runat="server">
<ItemTemplate>
<asp:Button ID="btnItemButton" runat="server"
Text='<%# Container.DataItem.ToString() %>'
CommandArgument='<%# Container.DataItem.ToString() %>'
/>
</ItemTemplate>
</asp:Repeater>
编辑再次审核您的代码后,我发现您在按钮上指定了public void Repeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
SaveUserInputsAction();
SaveDataAction();
lblTestMessage.Text = e.CommandArgument.ToString();
GetItemDetails(e.CommandArgument.ToString());
GetCostFactors(e.CommandArgument.ToString());
}
。如果您将其更改为CommandName="repeater_ItemCommand"
,它实际上可能有效。我有点像在OnCommand="repeater_ItemCommand"
上指定事件处理程序,但它可能归结为个人偏好。