我想在页面之间传递facility_id。但是,数据列表中的链接按钮不起作用。我可以知道它为什么不工作以及如何使它工作吗?
提前谢谢你。
下面是.aspx文件中的代码:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="2" RepeatDirection="Horizontal" HorizontalAlign="Center" Width="70%" DataKeyField="facility_id" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<asp:Label ID="facility_idLabel" runat="server" Text='<%# Eval("facility_id") %>' Visible="False" />
<table style="width:100%;">
<tr>
<td style="height: 53px; width: 500px; text-align: right;">
<asp:Label ID="Label2" runat="server" CssClass="ClientFacility2ndTitle" Text='<%# Eval("facility_name") %>'></asp:Label>
</td>
<td class="lblLogin" style="height: 53px; width: 220px">
<asp:LinkButton ID="LinkButton1" runat="server" BorderStyle="None" CssClass="Button" CommandName="BookNow">Book Now</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WebConfigcs %>" SelectCommand="SELECT [facility_id], [facility_name] FROM [facility]"></asp:SqlDataSource> 同时,对于aspx.cs中的代码:
public partial class ClientFacility : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName == "BookNow")
{
MessageBox.Show(e.CommandArgument.ToString());
Response.Redirect("EditFacility.aspx?facility_id=" + e.CommandArgument.ToString());
}
}
}发布于 2021-03-06 01:35:02
您有链接按钮的CommandName,但没有commandArugment?
所以:
<asp:LinkButton ID="LinkButton1" runat="server"
BorderStyle="None" CssClass="Button"
CommandName="BookNow"
CommandArgument = '<%# Eval("facility_id") %>'
>Book Now</asp:LinkButton>因此,要获取e.CommandArugment,您需要在链接按钮中进行设置。
https://stackoverflow.com/questions/66492311
复制相似问题