需要一只手,它具有DataList中的一个链接(值),一个新页面和(存储值) [英] need a hand with a link (values) in a DataList, to a new page and (store value)

查看:93
本文介绍了需要一只手,它具有DataList中的一个链接(值),一个新页面和(存储值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试创建一个链接以将值发送到下一页,然后在此页上使用此值.

在数据列表中.

Hi
I''m trying to create a link to send a value to the next page, and then use this value on this page.

Inside a Datalist.

<asp:linkButton ID="Datalnk1" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "ID")%>' CommandName="lnk" PostBackURL='~/Page/Event/popup.aspx' runat="server"><%#DataBinder.Eval(Container.DataItem, "ID")%
></asp:Linkbutton>



链接检索正确的SQL信息(ID)并打开下一页Popup.aspx

页面Popup.aspx



link retrieves the correct SQL info (ID) and open the next page Popup.aspx

Page Popup.aspx

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <div id="meldpå"  runat="server">
         Event:
        <asp:Label ID="confirmlabel" runat="server"></asp:Label>
        <br />
        <br />
        <asp:TextBox ID="name1" runat="server">Navn:</asp:TextBox>
        <br />
        <br />
<asp:Button ID="inexsql1" runat="server" Text="Send !!" OnClick="inexsql1_Click" />



代码文件Popup.aspx.vb



codefile Popup.aspx.vb

Partial Class Page_Event_popupPage
    Inherits System.Web.UI.Page

    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim name As String

    Public Sub Page_Load()
        Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("MainContent"), ContentPlaceHolder)

        Dim ID As String = String.Empty
        If Not String.IsNullOrEmpty(Request.QueryString("ID")) Then
            ID = Request.QueryString("ID")
        End If

        confirmlabel.Text = "ID"

    End Sub

    Protected Sub inexsql1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("MainContent"), ContentPlaceHolder)

        Dim name As TextBox = TryCast(Page.FindControl("name1"), TextBox)

        con = New SqlConnection("Data Source=VINYW8;Initial Catalog=Events;Integrated Security=True")
        cmd = New SqlCommand("INSERT INTO Påmeldt (Event, Navn)VALUES(@R1, @R2)", con)
        cmd.Parameters.AddWithValue("@R1", ID)
        cmd.Parameters.AddWithValue("@R2", name.Text)
        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub
End Class



麻烦的是,我没有获得指向下一页的链接中的值,并且我认为第一页中的代码有错误.
但我不确定获取并存储以供以后使用是否正确. (在弹出页面上)
并且我将Master.Page与内容占位符一起使用.



trouble is that I do not get the value in the link with me to the next page, and i think the code in the first page has an error.
but I''m not sure if get and store, to use later on is correct to. (on popup page)
and I use Master.Page with content placeholders.

推荐答案

您想将ID作为查询字符串发送,但在以下位置未添加查询字符串:
You want to send the ID as querystring but there is no querystring added in:
PostBackURL='~/Page/Event/popup.aspx'

,这就是为什么您在下一页上什么都没得到的原因. 您需要使用

that is why you are not getting anything on next page.
You need to use

<%#DataBinder.Eval(Container.DataItem, "ID")%>

将查询字符串添加到PostBackURL

祝你好运

to add a querystring in the PostBackURL

Good luck


这篇关于需要一只手,它具有DataList中的一个链接(值),一个新页面和(存储值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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