首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用链接按钮在页面之间传值?

如何使用链接按钮在页面之间传值?
EN

Stack Overflow用户
提问于 2021-03-05 20:06:58
回答 1查看 37关注 0票数 0

我想在页面之间传递facility_id。但是,数据列表中的链接按钮不起作用。我可以知道它为什么不工作以及如何使它工作吗?

提前谢谢你。

下面是.aspx文件中的代码:

代码语言:javascript
复制
<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中的代码:

代码语言:javascript
复制
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()); 
            }
        }
         
    }
EN

回答 1

Stack Overflow用户

发布于 2021-03-06 01:35:02

您有链接按钮的CommandName,但没有commandArugment?

所以:

代码语言:javascript
复制
<asp:LinkButton ID="LinkButton1" runat="server" 
   BorderStyle="None" CssClass="Button" 
   CommandName="BookNow"
   CommandArgument = '<%# Eval("facility_id") %>'
       >Book Now</asp:LinkButton>

因此,要获取e.CommandArugment,您需要在链接按钮中进行设置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66492311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档