简体   繁体   English

从ASP.Net gridview将多个值传递到查询字符串

[英]Passing multiple values into query string from ASP.Net gridview

I am creating a ticket sales application and I am having a little trouble with the passing some of the final values I needed. 我正在创建票务销售应用程序,在传递一些我需要的最终值时遇到了一些麻烦。
I need the event ID from the ticket that is being purchased but I fill the form I need with the ticket ID already. 我需要购买机票的事件ID,但是我已经用机票ID填写了所需的表格。 It is being passed already on the page from the previous page when I select the event I need. 当我选择所需的事件时,它已经在上一页的页面上传递了。
I need a way to convert the event ID from the label that is hidden on the page and pass it to the final page, along with the ticket ID as well (the ticket ID is what is being passed). 我需要一种方法,将事件ID从页面上隐藏的标签转换为事件ID,并将其与票证ID一起传递到最终页面(票证ID就是所传递的内容)。
Here is what I am working with: 这是我正在使用的:

<asp:GridView ID="grdvSeats" runat="server" DataKeyNames="SeatID" 
              AutoGenerateColumns="False" allowsorting="false" AllowPaging="false" 
              emptydatatext="No records match the criteria provided." BorderWidth = "1px">
     <Columns>
        <asp:HyperLinkField DataTextField="SeatName" 
                            DataNavigateUrlFields="SeatID" 
                            DataNavigateUrlFormatString="~/CheckOut.aspx?id={0}**&eID=lblEventID.Text**" 
                            HeaderText="Name" SortExpression="SeatName" /> 
     </Columns>
</asp:GridView>

OK, I don't completely follow that, but I think what you're saying is that from the first page, you pass the event ID, and then on this page, you assign the seat ID, and then you pass both of them to the final page. 好的,我并没有完全遵循,但是我想说的是,从第一页开始,您传递事件ID,然后在此页面上,分配席位ID,然后同时传递两者到最后一页。 My suggestion is based on that assumption, but if I've got the order wrong, you can adjust appropriately. 我的建议基于该假设,但是如果我的订单有误,则可以进行适当调整。

You might have to set your DataNavigateUrlFormatString from code-behind. 您可能必须从后台代码设置DataNavigateUrlFormatString I'm assuming (since you mention the Event ID being set in a label) that you have it available in the code-behind. 我假设(因为您提到了在标签中设置的事件ID)您在后面的代码中可以使用它。 So, somewhere before you call DataBind on the GridView , execute the following code: 因此,在调用GridView上的DataBind之前,执行以下代码:

// I'm assuming this is the 1st column, as it was in your grid example
HyperLinkField hfield = grdvSeats.Columns[0] as HyperLinkField;           
string urlFormat = "~/CheckOut.aspx?id={0}&eID=" + eventID.ToString();
hfield.DataNavigateUrlFormatString = urlFormat;

Thus your DataNavigateUrlFormatString will reflect your EventID, and databinding will assign the SeatID in your GridView. 因此,您的DataNavigateUrlFormatString将反映您的EventID,并且数据绑定将在GridView中分配SeatID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM