asp.net中的运行时间表 [英] run time table in asp.net

查看:75
本文介绍了asp.net中的运行时间表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生/女士
我在vb.net中创建了一个运行时间表.我使用了一些控件,并通过数据表的对象将其从数据库绑定.但是当我单击button(Book)时出现了问题,我想选择控件的所有值或id都像复选框,然后选择dropdownlist的itme,但是我无法罚款通过OnclientClick事件获得全部值.
我的代码和生成的表已给定,请看一眼,如果有任何帮助,请帮帮我.
谢谢

Dear sir/Mam
i hv created a run time table in vb.net. i used some controle and bind it from database via a object of data table.but there is a problem when i click on button(Book) i want all values or id of select controle like checkbox and select itme of dropdownlist but i m unable to fine the value of all through OnclientClick event.
my code and generated table is as given plz take a glance and if there is any ans plz help me.
thanks

Code is here---------------------------------

Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.UI.WebControls
Partial Class RunTimeTable
    Inherits System.Web.UI.Page
    Dim ConClass As New ConnectionClass
    Dim dt As New DataTable
    Dim td As New TableCell
    Dim td1 As New TableCell
    Dim td2 As New TableCell
    Dim td3 As New TableCell
    Dim td4 As New TableCell
    Dim td5 As New TableCell
    Dim td6 As New TableCell
    Dim td7 As New TableCell

    Dim tr As New TableRow
    Dim btn As New Button
    Dim chk As New CheckBox
    Dim rdo As New RadioButton
    Dim Cmb As New DropDownList
    Dim i As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        FillTable()

    End Sub
    Public Sub Concheck()
        If Me.ConClass.Con.State = Data.ConnectionState.Open Then Me.ConClass.Con.Close()
        Me.ConClass.Conn()
        Me.ConClass.Con.Open()
    End Sub

    Public Sub FillTable()
        Me.Concheck()
        Me.ConClass.cmd.CommandText = "SELECT RoomType, Rent, Rent_SingleOccupy, NoOfBed FROM RoomType WHERE NoOfBed = '02'"
        Me.ConClass.ad.Fill(dt)
        If dt.Rows.Count > 0 Then
            '---------------------Code for header Line---------------------------
            td1 = New TableCell
            td1.Text = "Room type"
            td2 = New TableCell
            td2.Text = "Complementry Facility"
            td3 = New TableCell
            td3.ColumnSpan = 4
            td3.Text = "Rent"
            td4 = New TableCell
            td4.Text = "Select"

            tr = New TableRow
            tr.BackColor = Drawing.Color.SteelBlue
            tr.ForeColor = Drawing.Color.White
            tr.Controls.Add(td1)
            tr.Controls.Add(td2)
            tr.Controls.Add(td3)
            tr.Controls.Add(td4)
            Me.MyTable.Controls.Add(tr)
            '---------------------End Code for header Line---------------------------
            '--------------------Code for Second Header Line------------------------

            td1 = New TableCell

            td2 = New TableCell

            td3 = New TableCell
            td3.Text = "Single Ocp."

            td4 = New TableCell
            td4.Text = "Select"

            td5 = New TableCell
            td5.Text = "Double Ocp."

            td6 = New TableCell
            td6.Text = "Select"

            td7 = New TableCell


            tr = New TableRow
            tr.BackColor = Drawing.Color.SkyBlue
            tr.ForeColor = Drawing.Color.Red
            tr.Controls.Add(td1)
            tr.Controls.Add(td2)
            tr.Controls.Add(td3)
            tr.Controls.Add(td4)
            tr.Controls.Add(td5)
            tr.Controls.Add(td6)
            tr.Controls.Add(td7)

            Me.MyTable.Controls.Add(tr)
            '--------------------End Code for Second Header Line------------------------
            '-------------------------Code for Data Row--------------------------------
            While i < dt.Rows.Count
                td1 = New TableCell
                td1.Text = dt.Rows(i).Item(0).ToString

                td2 = New TableCell
                td2.Text = "---"

                td3 = New TableCell
                td3.Text = dt.Rows(i).Item(1).ToString

                td4 = New TableCell
                chk = New CheckBox
                td4.Controls.Add(chk)

                td5 = New TableCell
                td5.Text = dt.Rows(i).Item(2).ToString

                td6 = New TableCell
                chk = New CheckBox
                td6.Controls.Add(chk)

                td7 = New TableCell
                Cmb = New DropDownList
                Cmb.ID = "DropDown" & dt.Rows(i).Item(2).ToString
                Cmb.Items.Add("<-Select->")
                Cmb.Items.Add("1")
                Cmb.Items.Add("2")
                Cmb.Items.Add("3")
                Cmb.Items.Add("4")
                td7.Controls.Add(Cmb)


                tr = New TableRow
                tr.Controls.Add(td1)
                tr.Controls.Add(td2)
                tr.Controls.Add(td3)
                tr.Controls.Add(td4)
                tr.Controls.Add(td5)
                tr.Controls.Add(td6)
                tr.Controls.Add(td7)
                Me.MyTable.Controls.Add(tr)

                i = i + 1
            End While
            '-------------------------End Code for Data Row--------------------------------
            '-------------------------Code for Book button Line------------------
            td1 = New TableCell

            td2 = New TableCell

            td3 = New TableCell

            td4 = New TableCell

            td5 = New TableCell

            td6 = New TableCell

            td7 = New TableCell
            btn = New Button
            btn.Text = "Book Now"
            btn.BackColor = Drawing.Color.AliceBlue
            btn.ForeColor = Drawing.Color.Blue
            btn.ToolTip = "Hello arti"
            Dim msg As String '= Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "OnClick", "<script language=javascript>alert('this is me')</script>")
            btn.OnClientClick = "GetDropDownValue('<%= dropDown.ClientID %>')"
            td7.Controls.Add(btn)


            tr = New TableRow
            tr.BackColor = Drawing.Color.SkyBlue
            tr.ForeColor = Drawing.Color.Red
            tr.Controls.Add(td1)
            tr.Controls.Add(td2)
            tr.Controls.Add(td3)
            tr.Controls.Add(td4)
            tr.Controls.Add(td5)
            tr.Controls.Add(td6)
            tr.Controls.Add(td7)

            Me.MyTable.Controls.Add(tr)

            '-------------------------Code for Book button Line------------------


        End If '------------------For dt.rows.count

    End Sub
End Class

推荐答案

您在每次回发中都调用填充表.因此,您将失去viewstate,这意味着您的选择将被重置.将FillTable调用放在!IsPostback块中.
You call fill table on every postback. You therefore lose viewstate, which means your selections are reset. Put the FillTable call in a !IsPostback block.


这篇关于asp.net中的运行时间表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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