我试图使用CommandNames / CommandArguments在我的转发器中为我的按钮设置一个onclick事件,但我似乎无法通过单击按钮来触发该事件,所以很明显我&#39愚蠢的做事。
我的前端就像:
<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();
当我点击按钮时,它没有。