尝试使用隐藏字段来存储选定的产品 ID:
HTML:
<script type="text/javascript">
function addProduct(prid) {
// assign the product ID to the hidden field's value
document.getElementById("<%= hidProductId.ClientID %>").value = prid;
}
</script>
<asp:DataList ID="DataList1" runat="server" DataKeyField="Prd_id" DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click" OnClientClick="<%# "addProduct('" + Eval("Prd_id") + "');" %>" ></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<asp:HiddenField ID="hidProductId" runat="server" />
后面的代码:
protected void btnAdd_Click(object sender, EventArgs e)
{
var productId = hidProductId.Value;
}