在中继器来传递会话变量链接按钮 [英] link button in repeater to pass session variable

查看:115
本文介绍了在中继器来传递会话变量链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个中继器,列出了我的自定义数据,现在我想要做的是一个变量传递从一个网页到另一个使用ASP:LinkBut​​ton的。我遇到的问题是,当我去调用子程序我的链接按钮,它不被认可。我看着找不到一个中继器但我不认为它会在这种情况下工作。这里是我的code:

 < ASP:直放站ID =rptList=服务器的EnableViewState =假的DataSourceID =SqlDataSource3>
<&ItemTemplate中GT;
    < D​​IV>
    &所述p为H.;
    < B>标题:LT; / B> < ASP:LinkBut​​ton的ID =lbnCookieVar的OnClick =lbnCookieVar_Click文本='<%#的eval(JOB_TITLE)%>' =服务器/> < BR />
    < B>状态:其中; / B><%#的eval(状态)%GT;< BR />
    < B>部:< / B><%#的eval(部门)%GT;< BR />
    < B>日期位置可用:LT; / B><%#的eval(Date_Position_Available)%>< BR />
    &所述; / P>
    < / DIV>
< / ItemTemplate中>
< / ASP:直放站>

下面是背后

在code

 保护无效lbnCookieVar_Click(对象发件人,EventArgs的发送)
{
    会话[数据] = lbnCookieVar.Text;
    的Response.Redirect(Application.aspx);
}


解决方案

丑和你正在比您需要的。

这种方式比较困难

你为什么不使用Repeater的ItemCommand日常挑这个吗?然后,你只是通过你想要做什么的CommandArgument。

 < ASP:直放站ID =rptList=服务器的EnableViewState =假
    的DataSourceID =SqlDataSource3OnItemCommand =rptList_ItemCommand>
<&ItemTemplate中GT;
    < D​​IV>
    &所述p为H.;
    < B>标题:LT; / B> < ASP:LinkBut​​ton的ID =lbnCookieVar的CommandText =点击CommandArgument ='<%#的eval(JOB_TITLE)%>'文字='<%#的eval(JOB_TITLE)%>' =服务器/> < BR />
    < B>状态:其中; / B><%#的eval(状态)%GT;< BR />
    < B>部:< / B><%#的eval(部门)%GT;< BR />
    < B>日期位置可用:LT; / B><%#的eval(Date_Position_Available)%>< BR />
    &所述; / P>
    < / DIV>
< / ItemTemplate中>
< / ASP:直放站>

code背后:

我不知道是谁改变了我的code,但你错了。如果你这样做,正是因为它是这是你做的方式。我错把单引号括起来的点击,当它应该是双引号。

 保护无效rptList_ItemCommand(对象发件人,CommandEventArgs E)
{
   如果(e.CommandName ==点击)
   {
       会话[数据] = e.CommandArgument.ToString();
       的Response.Redirect(Application.aspx);
   }
}

I have a repeater listing out my custom data, now what I want to do is pass on a variable from one page to another using a asp:linkbutton. The problem I am having is that when I go to call my link button in the subroutine its not being recognized. I looked at Can't find a link button in a repeater but I do not think it will work in this case. Here is my code:

    <asp:Repeater ID="rptList" runat="server" EnableViewState="false" DataSourceID="SqlDataSource3">
<ItemTemplate>
    <div>
    <p>
    <b>Title: </b> <asp:LinkButton ID="lbnCookieVar" OnClick="lbnCookieVar_Click" Text='<%# Eval("Job_Title")%>' runat="server" /> <br />
    <b>Status: </b><%# Eval("Status")%><br />
    <b>Department: </b><%# Eval("Department")%><br />
    <b>Date Position Available: </b><%# Eval("Date_Position_Available")%><br />
    </p>
    </div>
</ItemTemplate>
</asp:Repeater>

here is the code behind

     protected void lbnCookieVar_Click(object sender, EventArgs e)
{
    Session["Data"] = lbnCookieVar.Text;
    Response.Redirect("Application.aspx");
}

解决方案

Ugly and you are making this way more difficult than you need to.

Why aren't you using the Repeater's ItemCommand routine to pick this up? Then you just pass the CommandArgument of what you want to do.

<asp:Repeater ID="rptList" runat="server" EnableViewState="false" 
    DataSourceID="SqlDataSource3" OnItemCommand="rptList_ItemCommand">
<ItemTemplate>
    <div>
    <p>
    <b>Title: </b> <asp:LinkButton ID="lbnCookieVar" CommandText="click" CommandArgument='<%# Eval("Job_Title")%>' Text='<%# Eval("Job_Title")%>' runat="server" /> <br />
    <b>Status: </b><%# Eval("Status")%><br />
    <b>Department: </b><%# Eval("Department")%><br />
    <b>Date Position Available: </b><%# Eval("Date_Position_Available")%><br />
    </p>
    </div>
</ItemTemplate>
</asp:Repeater>

Code Behind:

I don't know who changed my code but you are mistaken. If you do this exactly as it is this is the way you do it. I had mistakenly put single quotes around "click" when it should have been double quotes.

protected void rptList_ItemCommand(object sender, CommandEventArgs e)
{
   if (e.CommandName == "click")
   {
       Session["Data"] = e.CommandArgument.ToString();
       Response.Redirect("Application.aspx");
   }
}

这篇关于在中继器来传递会话变量链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆