【问题标题】:How to set the sessions in .aspx according to the rows如何根据行在 .aspx 中设置会话
【发布时间】:2012-11-11 17:09:31
【问题描述】:

我面临以下问题:

当我根据我的要求在我的 aspx 中设置会话时:

<Columns>
<asp:TemplateField ItemStyle-Width="10px">
<ItemTemplate>
<a id="btnShowPopup5" runat="server" class="thickbox" href='<%#"PopUp.aspx?AR=2"+"&TBiframe=true&height=530&width=750"%>'
<asp:Image ID="Image23" runat="server" ToolTip="Back" ImageUrl="Images/cross.png" /></a>
<asp:HiddenField ID="HDN_TaskCode" Value='<%# Session["s_TaskCode"] = DataBinder.Eval(Container.DataItem, "TaskCode") %>'
runat="server" />

我注意到:Session["s_TaskCode"] 始终设置为 gridview 中的第一行任务代码值!!

这不是我想要的。

我想根据行设置会话。

说我的 gridview 有两行:

  • 第一个task_code值为7
  • 第二个task_code值为10

我想根据我点击的超链接设置正确的会话值。

像数据键。

注意:我想在 .aspx 而不是 .cs 中设置会话。

【问题讨论】:

    标签: c# asp.net session gridview eval


    【解决方案1】:

    您的代码中只使用了一个会话变量 (Session["s_TaskCode"])。那么,如何在其中保留多个值。它将始终包含上次写入的值。

    要在会话中按行存储值,您必须执行以下操作:

    Session["s_TaskCode" + rowIndex]

    这里,rowIndex 是

    所以你可以像这样使用:&lt;%# Session["s_TaskCode" + Container.DataItemIndex] %&gt;

    编辑:

    而不是session,为什么不在'btnShowPopup5' href url QueryString参数中传递TaskCode的值:

    href='<%#"PopUp.aspx?AR=2"+"&TBiframe=true&height=530&width=750&" + DataBinder.Eval(Container.DataItem, "TaskCode") %>'
    

    【讨论】:

    • 然后通过这种方式,我将使用第一行值加上行索引来设置会话!
    • 是的,但是您可以随时检查 rowIndex = 0 是否然后使用 Session["s_TaskCode"]。
    • 我也得到编译错误The name 'rowIndex' does not exist in the current context
    • 会给你rowIndex。
    • @just_name 您可以在将敏感数据传递给 QueryString 之前对其进行编码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2014-04-17
    • 2020-08-08
    • 2013-06-27
    • 1970-01-01
    • 2019-07-17
    • 2013-12-07
    相关资源
    最近更新 更多