1

我面临着从文本框中读取值的困难情况,该文本框动态添加到 AjaxTabContainer 的 TabPanel 内的 gridview 中。

请注意,所有控件都是根据用户选项动态添加的。

顺序如下:

  
Design Time:
One Panel and other user options (date & some other fields)

Run Time:
- Add AjaxTab container & Tab Panel which is vary upon user filter (Tab created based on db -records)
- Inside each tab, added the GridView with dataset
- Add some textbox into each of GridView Line

在页面上:我可以使用带有文本框的 gridview 成功显示选项卡控件(*如下)动态文本框 现在,当用户单击“更新”按钮时,如何读取每个文本框中的值?我尝试使用 FindControls,但没有。

我的代码:-


Private Sub DynamicTabGVLoad(ByVal seqno As String)
        createTab()
        ds = allotmentdb.getRoomType()
        For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
            Dim tabcontent As New Control()
            Dim tbldynamic As New Table()
            Dim tbrdynamic As New TableRow()
            Dim tbcdynamic As New TableCell()           
            Dim roomtypekey As String
            roomtypekey = ds.Tables(0).Rows(i)("roomtypekey").ToString()
            Dim gv_alines As New GridView
            gv_alines.AutoGenerateColumns = True
            gv_alines.Attributes.Add("runat", "server")
            Dim ds1 As New Data.DataSet()
            ds1 = allotmentdb.getAllotmentLinesTabGV(roomtypekey, seqno, System.DateTime.Now.ToString(("yyyy-MM-dd")))
            gv_alines.EmptyDataText = "No Record Found!"
            'gv_alines.ShowHeaderWhenEmpty = True
            gv_alines.DataSource = ds1
            gv_alines.DataBind()
            If gv_alines.Rows.Count > 0 Then
                gv_alines.HeaderRow.Cells(0).Visible = False
                gv_alines.HeaderRow.Cells(1).Visible = False
                gv_alines.HeaderRow.Cells(4).Visible = False
                For Each gvr As GridViewRow In gv_alines.Rows
                    gvr.Cells(0).Visible = False
                    gvr.Cells(1).Visible = False
                    gvr.Cells(4).Visible = False
                    Dim txtInternetRoom As New TextBox()
                    txtInternetRoom.ID = "txtInternetRoom"
                    txtInternetRoom.Text = gvr.Cells(5).Text
                    txtInternetRoom.Style.Add("text-align", "right")
                    txtInternetRoom.Width = 100
                    gvr.Cells(5).Controls.Add(txtInternetRoom)
                    Dim txtInternetRate As New TextBox()
                    txtInternetRate.ID = "txtInternetRate"
                    txtInternetRate.Text = FormatNumber(gvr.Cells(6).Text, 2)
                    If txtInternetRate.Text = "0.00" Then txtInternetRate.Text = "NA"
                    txtInternetRate.Style.Add("text-align", "right")
                    txtInternetRate.Width = 100
                    gvr.Cells(6).Controls.Add(txtInternetRate)
                    Dim txtInternetRate2 As New TextBox()
                    txtInternetRate2.ID = "txtInternetRate2"
                    txtInternetRate2.Text = FormatNumber(gvr.Cells(7).Text)
                    If txtInternetRate2.Text = "0.00" Then txtInternetRate2.Text = "NA"
                    txtInternetRate2.Style.Add("text-align", "right")
                    txtInternetRate2.Width = 100
                    gvr.Cells(7).Controls.Add(txtInternetRate2)
                    Dim txtInternetRate3 As New TextBox()
                    txtInternetRate3.ID = "txtInternetRate3"
                    txtInternetRate3.Text = FormatNumber(gvr.Cells(8).Text)
                    If txtInternetRate3.Text = "0.00" Then txtInternetRate3.Text = "NA"
                    txtInternetRate3.Style.Add("text-align", "right")
                    txtInternetRate3.Width = 100
                    gvr.Cells(8).Controls.Add(txtInternetRate3)
                    Dim txtInternetRate4 As New TextBox()
                    txtInternetRate4.ID = "txtInternetRate4"
                    txtInternetRate4.Text = FormatNumber(gvr.Cells(9).Text)
                    If txtInternetRate4.Text = "0.00" Then txtInternetRate4.Text = "NA"
                    txtInternetRate4.Style.Add("text-align", "right")
                    txtInternetRate4.Width = 100
                    gvr.Cells(9).Controls.Add(txtInternetRate4)
                Next
            Else               
            End If
            tbcdynamic.Controls.Add(gv_alines)
            tbrdynamic.Cells.Add(tbcdynamic)
            tbldynamic.Rows.Add(tbrdynamic)
            tabcontent.Controls.Add(tbldynamic)
            ajxTab.Tabs(i).Controls.Add(tabcontent)
        Next
        pnlDynamic.Controls.Add(ajxTab)
    End Sub
    Private Sub createTab()
        ds = allotmentdb.getRoomType()
        ajxTab = New AjaxControlToolkit.TabContainer()
        ajxTab.Attributes.Add("runat", "server")
        'Me.Controls.Add(ajxTab)
        For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
            Dim tbpnlDynamic As New TabPanel()
            tbpnlDynamic.Attributes.Add("runat", "server")
            tbpnlDynamic.HeaderText = ds.Tables(0).Rows(i)("RoomType").ToString()
            tbpnlDynamic.ID = ds.Tables(0).Rows(i)("RoomTypeKey").ToString()
            tbpnlDynamic.Visible = True
            ajxTab.Tabs.Add(tbpnlDynamic)
            ajxTab.ActiveTabIndex = 0
        Next
    End Sub

我非常迫切需要它。提前致谢!

4

0 回答 0