我正在尝试使用 CommandNames/CommandArguments 为我的转发器中的按钮设置一个 onclick 事件,但我似乎无法在单击按钮时触发该事件,所以显然我在做一些愚蠢的事情。
我的前端是这样的:
<asp:Repeater runat="server" ID="rptCompany" OnItemCommand="rptCompanyCommand" OnItemDataBound="rptCompanyBound">
<ItemTemplate>
<ul>
<li><asp:Label CssClass="selectedCompany" runat="server" ID="lnkCompany"></asp:Label> <asp:Button CommandName="Select" CommandArgument='<%# Eval("ComId") %>' runat="server" ID="btnSelect" Text="Select" /></li>
</ul>
</ItemTemplate>
</asp:Repeater>
后端代码为:
protected void loadResults()
{
dtVCompany = new components.db.PIDSDB.vCompanyDataTable();
dtVCompany = taVCompany.GetCompaniesByName(txtSearch.Text + "%");
rptCompany.DataSource = dtVCompany;
rptCompany.DataBind();
}
protected void rptCompanyBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
DataRowView nRow = null;
switch (e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
nRow = (DataRowView)e.Item.DataItem;
((Label)e.Item.FindControl("lnkCompany")).Text = "" + nRow["Company"] + "|" + nRow["ComId"];
break;
}
}
protected void rptCompanyCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "Select":
{
String selectedID = e.CommandArgument.ToString();
}
break;
default:
{
}
break;
}
}
除非我弄错了,否则我会认为它会在线上达到我的断点:
String selectedID = e.CommandArgument.ToString();
当我单击按钮时,它没有。