发送'<%#Eval(“item”)%>'在ASP.Net中使用VB代码

时间:2016-11-14 09:39:20

标签: asp.net vb.net

我有一个问题,关于网站上的新录像机想要注册一个特定的课程谁应该通过点击注册链接..然后通过注册码输入数据..确定..然后发送数据到电子邮件代码工作正常..但我的问题在这里..如何为电子邮件带来这个会话数据?我如何为注册到电子邮件的新用户发送Eval(“item”): 课程名 天......

代码如下:

Schedule.aspx:

<asp:Repeater ID="RepeaterCourse" runat="server">
    <ItemTemplate>
        <div style="width: 30%;">
            <asp:Label ID="LabelEnglishName" runat="server" CssClass="LabelReg"><%# Eval("EnglishName")%></asp:Label>
        </div>
        <label id="CityCountry" style="float: left; margin-left: -15px; margin-right: 15px; color: maroon; font-size: 13px; text-align: center; width: 20%; margin-top: 20px;"><%# Eval("CityCountry")%></label>
        <label id="StartCourse" style="float: left; color: maroon; font-size: 13px; width: 20%; margin-left: 15px; margin-right: -13px; margin-top: 20px;"><%# Eval("StartCourse", "{0:MMM dd, yyyy}")%></label>
        <label id="EndCourse" style="float: left; color: maroon; font-size: 13px; width: 20%; margin-top: 20px;"><%# Eval("EndCourse", "{0:MMM dd, yyyy}")%></label>
        <label id="Days" style="float: left; width: 20%; margin-top: 20px;"><%# Eval("Days")%></label>
        </div>
    </ItemTemplate>
</asp:Repeater>

VB.Net代码

Public Function FindCourse() As DataTable
        GetConnection()
        Dim SQL As String = "SELECT DISTINCT ScheduleNew.ScheduleID, ScheduleNew.CourseID , ScheduleNew.CityID, ScheduleNew.StartCourse, ScheduleNew.EndCourse, ScheduleNew.Days, ScheduleNew.CountryID, ScheduleNew.CategoryID, ScheduleNew.FieldID , ScheduleNew.Note, ScheduleNew.MonthsID , CoursesNew.CourseLogo , CoursesNew.EnglishName , (City.CityName +', '  +Country.CountryName) AS CityCountry  FROM ScheduleNew ,CoursesNew , Country , City , Months  Where Country.CountryID=City.CountryID AND City.CityID=ScheduleNew.CityID AND CoursesNew.CourseID=ScheduleNew.CourseID AND Months.MonthsID = ScheduleNew.MonthsID "
 
        Dim dt As New DataTable
        Dim da As New SqlDataAdapter(SQL, Conn)
 
        If CountryID <> 0 Then
            da.SelectCommand.CommandText = " AND City.CountryID = @CountryID"
            da.SelectCommand.Parameters.Add("@CountryID", SqlDbType.Int).Value = CountryID
        End If
 
        If ScheduleID <> 0 Then
            da.SelectCommand.CommandText &= "And ScheduleNew.ScheduleID =@ScheduleID"
            da.SelectCommand.Parameters.Add("@ScheduleID", SqlDbType.Int).Value = ScheduleID
        End If
 
        If CourseID <> 0 Then
            da.SelectCommand.CommandText &= "And ScheduleNew.CourseID =@CourseID"
            da.SelectCommand.Parameters.Add("@CourseID", SqlDbType.Int).Value = CourseID
        End If
 
        If CityID <> 0 Then
            da.SelectCommand.CommandText &= " And ScheduleNew.CityID =@CityID"
            da.SelectCommand.Parameters.Add("@CityID", SqlDbType.Int).Value = CityID
        End If
 
        If StartCourse <> "" Then
            da.SelectCommand.CommandText &= " And ScheduleNew.StartCourse Like @StartCourse "
            da.SelectCommand.Parameters.Add("@StartCourse", SqlDbType.DateTime).Value = "%" & StartCourse & "%"
        End If
 
        If EndCourse <> "" Then
            da.SelectCommand.CommandText &= " And ScheduleNew.EndCourse Like @EndCourse"
            da.SelectCommand.Parameters.Add("@EndCourse", SqlDbType.DateTime).Value = "%" & EndCourse & "%"
        End If
 
        If MonthsID <> 0 Then
            da.SelectCommand.CommandText &= " And ScheduleNew.MonthsID=@MonthsID"
            da.SelectCommand.Parameters.Add("@MonthsID", SqlDbType.Int).Value = MonthsID
        End If
 
        If CategoryID <> 0 Then
            da.SelectCommand.CommandText &= " And ScheduleNew.CategoryID=@CategoryID"
            da.SelectCommand.Parameters.Add("@CategoryID", SqlDbType.Int).Value = CategoryID
        End If
 
        If FieldID <> 0 Then
            da.SelectCommand.CommandText &= " And ScheduleNew.FieldID=@FieldID"
            da.SelectCommand.Parameters.Add("@FieldID", SqlDbType.Int).Value = FieldID
        End If
 
        If Days <> 0 Then
            da.SelectCommand.CommandText &= " And ScheduleNew.Days=@Days"
            da.SelectCommand.Parameters.Add("@Days", SqlDbType.int).Value = Days
        End If
 
 
        da.SelectCommand.CommandText &= " order by StartCourse asc"
 
        Try
            da.Fill(dt)
        Catch ex As Exception
            'Error
        Finally
            Conn.Close()
        End Try
        Return dt
    End Function

页面图片:

http://www.directupload.net/file/d/4539/spzkruw8_png.htm

http://www.directupload.net/file/d/4539/dvndgvpy_png.htm

1 个答案:

答案 0 :(得分:0)

您可以使用OnItemCommand事件。将事件添加到Repeater。

<asp:Repeater ID="RepeaterCourse" runat="server" OnItemCommand="RepeaterCourse_ItemCommand">

使用CommandNameCommandArgument向Repeater模板添加一个按钮。

<asp:Button ID="Button1" runat="server" Text="Button" CommandName="emailCourse" CommandArgument='<%# Eval("item") %>' />

然后在代码背后。

Protected Sub RepeaterCourse_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
    'check if the commandname is the correct one (multiple buttons can use the same itemcommand)
    If (e.CommandName = "emailCourse") Then
        'get the value of the commandargument
        Dim itemID As String = e.CommandArgument.ToString

        'send the email here
    End If        
End Sub