Sozdanie Dynamicheskiy Linkbutton V Vb.net

Тема в разделе ".NET", создана пользователем Erik2006, 24 сен 2008.

  1. Erik2006

    Erik2006 Гость

    Privet Vsem!

    Stolknulsya s problemoy v VB.Net, potomu chto ego ne znayu, a delat nado :)

    Problema takaya: est web-stranisa (s rashireniem aspx), v ney tablisa (obichnaya 6x8), a v ney informasiya

    [​IMG]
    Screenshot #1

    Informasiya biretsya s bazi dannih SQL Server 2005, kotoraya sostoit iz kolonok: ID, Label, Weekday, Daytime i Content. V danniy moment v tablise, kotoraya otobrajena na web stranise, dannie idut s kolonki Label:

    [​IMG]
    Screenshot #2

    Mne teper nado sdelat ssilki na content, naprimer kogda klikaesh po tomu ili inomu "label"-u, chtob otkrivalsya sootvetstvuyeshiy content.

    Mne moy manager, on toje programmist i reshenie on znaet, emu eto 5 minut, no dlya menya eto poka temniy les :), Tak vot on skazal chto eto mojno sdelat s pomoshyu Dynamic LinkButton, tipa sdelal podskazku, ya i chital, i kopalsya cheta nikak :(

    Nadeus na vashu pomosh

    Za ranee spasibo
     
  2. Erik2006

    Erik2006 Гость

    spasibo za otziv!

    Tablisa sdelana na VB.net-e s ispolzovaniem HTML tegov

    Vot ishodniy kod (recipes.aspx):

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="reicepes.aspx.vb" Inherits="CookWell.Recipes"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>Recipes</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <span id="span_ListRecipes" runat="server"></span>
    </form>
    </body>
    </HTML>

    Vot ishodniy kod (recipes.aspx.vb):

    Imports System.Data

    Public Class Recipes
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents span_ListRecipes As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents LB_OpenContent As System.Web.UI.WebControls.LinkButton
    Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not IsPostBack() Then
    span_ListRecipes.InnerHtml = GetReciepes()
    End If
    End Sub

    Private Function GetReciepes() As String
    Dim strQuery As String = "SELECT * FROM WellProgram.T_CookWellReceipes ORDER BY DayTime, WeekDay"

    Dim da As New SqlClient.SqlDataAdapter(strQuery, ConfigurationSettings.AppSettings("Conn_WellProgram"))
    Dim tbl As New DataTable
    Dim strHTML As String = String.Empty

    da.Fill(tbl)

    ' Header
    'strHTML += "<table border = 1><tr><td>ID</td><td>Label</td><td>WeekDay</td><td>dayTime</td></tr>"
    'For Each row As DataRow In tbl.Select("DayTime = 'BreakFast'")
    'strHTML += "<tr>"
    'strHTML += "<td>" + row("ID").ToString + "</td>"
    'strHTML += "<td>" + row("Label").ToString + "</td>"
    'strHTML += "<td>" + row("WeekDay").ToString + "</td>"
    'strHTML += "<td>" + row("DayTime").ToString + "</td>"
    'strHTML += "</tr>"
    'Next

    'strHTML += "</Table>"

    strHTML += "<HR>"

    ' Header
    strHTML += "<table border = 1><tr><td></td>"
    ' Day i
    Dim i As Integer = 1
    While i < 8
    strHTML += "<td><b><center>Day " & i & "</center></b></td>"
    i += 1
    End While


    ' Breakfast
    strHTML += "<tr><td><b>BreakFast</b></TD>"
    For Each row As DataRow In tbl.Select("DayTime = 'BreakFast'")
    Dim lb As New LinkButton

    'With lb
    ' .ID = "lb_" & row("WeekDay").tostring.Replace("Day", String.Empty).Trim
    ' .Text = "..."
    'End With

    strHTML += "<td>" & row("Label").ToString & "</td>"
    Next

    ' Snack1
    strHTML += "<tr><td><b>Snack</b></TD>"
    For Each row As DataRow In tbl.Select("DayTime = 'Snack1'")
    Dim lb As New LinkButton

    'With lb
    ' .ID = "lb_" & row("WeekDay").tostring.Replace("Day", String.Empty).Trim
    ' .Text = "..."
    'End With

    strHTML += "<td>" & row("Label").ToString & "</td>"
    Next

    ' Snack1
    strHTML += "<tr><td><b>Lunch</b></TD>"
    For Each row As DataRow In tbl.Select("DayTime = 'Lunch'")
    Dim lb As New LinkButton

    'With lb
    ' .ID = "lb_" & row("WeekDay").tostring.Replace("Day", String.Empty).Trim
    ' .Text = "..."
    'End With

    strHTML += "<td>" & row("Label").ToString & "</td>"
    Next

    ' Snack1
    strHTML += "<tr><td><b>Snack</b></TD>"
    For Each row As DataRow In tbl.Select("DayTime = 'Snack2'")
    Dim lb As New LinkButton

    'With lb
    ' .ID = "lb_" & row("WeekDay").tostring.Replace("Day", String.Empty).Trim
    ' .Text = "..."
    'End With

    strHTML += "<td>" & row("Label").ToString & "</td>"
    Next

    ' Snack1
    strHTML += "<tr><td><b>Dinner</b></TD>"
    For Each row As DataRow In tbl.Select("DayTime = 'Dinner'")
    Dim lb As New LinkButton

    'With lb
    ' .ID = "lb_" & row("WeekDay").tostring.Replace("Day", String.Empty).Trim
    ' .Text = "..."
    'End With

    strHTML += "<td>" & row("Label").ToString & "</td>"
    Next

    ' End of the table
    strHTML += "</tr></Table>"




    GetReciepes = strHTML

    tbl.Dispose()
    da.Dispose()
    End Function

    Private Sub LB_OpenContent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LB_OpenContent.Click

    Dim strQuery As String = "SELECT TOP 1 * FROM WellProgram.T_CookWellReceipes ORDER BY DayTime, WeekDay"

    Dim da As New SqlClient.SqlDataAdapter(strQuery, ConfigurationSettings.AppSettings("Conn_WellProgram"))
    Dim tbl As New DataTable
    Dim strHTML As String = String.Empty

    da.Fill(tbl)

    Session("RecipesContent") = tbl.Rows(0)("Content").ToString

    Response.Redirect("ContentRecipes.aspx")


    tbl.Dispose()
    da.Dispose()
    End Sub
    End Class
     

Поделиться этой страницей