Unable to read link from gridview? - asp.net

I am trying to populate hyperlink1 text on my webpage with the link from the selected gridview row. I am not able to get any value back. Any ideas?
Private Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToString(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(index)
Me.NameTextBox.Text = Server.HtmlDecode(row.Cells(1).Text)
Me.Product1DropDown.SelectedValue = Server.HtmlDecode(row.Cells(2).Text)
Me.Product2DropDown.SelectedValue = Server.HtmlDecode(row.Cells(3).Text)
Me.JobNumberTextBox.Text = Server.HtmlDecode(row.Cells(4).Text)
Me.AdTextBox.Text = Server.HtmlDecode(row.Cells(5).Text)
Me.MediaTypeDropDown.SelectedValue = Server.HtmlDecode(row.Cells(6).Text)
Me.AuthorDropDown.SelectedValue = Server.HtmlDecode(row.Cells(7).Text)
Me.PublicationDropDown.SelectedValue = Server.HtmlDecode(row.Cells(8).Text)
Me.RunDatesTextBox.Text = Server.HtmlDecode(row.Cells(9).Text)
Me.CostTextBox.Text = Server.HtmlDecode(row.Cells(10).Text)
Me.CostCenterTextBox.Text = Server.HtmlDecode(row.Cells(11).Text)
Me.CommentsTextBox.Text = Server.HtmlDecode(row.Cells(12).Text)
Me.HyperLink1.Text = Server.HtmlDecode(row.Cells(13).Text)
Me.HyperLink1.NavigateUrl = Server.HtmlDecode(row.Cells(13).Text)
Me.TextBox1.Text = Server.HtmlDecode(row.Cells(14).Text)
Label14.Text = "Update"
End If
End Sub

Related

I want to make the same condition on all row data bound cell , How to do it?

I want to make all of the cell have their own color
eg,
status = v ---> color Yellow
status = P.H ---> Color Green
status = H -----> Blue
else status ----> Red
This is the code of that situation
Protected Sub gvMonthlyReport_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Header Then
e.Row.CssClass = "HeaderRow"
e.Row.HorizontalAlign = HorizontalAlign.Center
e.Row.VerticalAlign = VerticalAlign.Middle
End If
'If e.Row.RowType = DataControlRowType.DataRow Then
' e.Row.CssClass = "cellRow"
'End If
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = e.Row.Cells(17)
Dim status As String = cell.Text
If status = "v" Then
cell.BackColor = Color.Yellow
ElseIf status = "H" Then
cell.BackColor = Color.Blue
ElseIf status = "P.H" Then
cell.BackColor = Color.Green
Else
cell.BackColor = Color.Red
End If
End If
End Sub
this code i have done give me the output color only one column like this
image
output image
actually i want all column , can someone show me?
You have hardcoded cell number 17, but you need to use a loop in the RowDataBound event.
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim i As Integer = 0
Do While (i < e.Row.Cells.Count)
Dim cell As TableCell = CType(e.Row.Cells(i),TableCell)
cell.BackColor = Color.Red
i = (i + 1)
Loop
End If

Clear Form Button is not working correctly

Created a master.page and added several content pages. Imported the code from previous webform into one of my content pages. Now the clear button is not working correctly. It will not clear the textboxes or checkboxes. greatly appreciate any help. The form worked perfectly as a standalone page.
vb code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Num1, Num2, Num3, Num4 As Double
Dim Opt1, Opt2, Opt3, Opt4 As Double
Dim BaseTotal, OptionTotal, GrandTotal, Tax As Double
Num1 = Val(TextBox1.Text) * 1500
Num2 = Val(TextBox2.Text) * 70
Num3 = Val(TextBox3.Text) * 90
Num4 = Val(TextBox4.Text) * 130
If CheckBox1.Checked Then
Opt1 = 175
End If
If CheckBox2.Checked Then
Opt2 = 400
End If
If CheckBox3.Checked Then
Opt3 = 100
End If
If CheckBox4.Checked Then
Opt4 = 200
End If
' sum of checkboxes
OptionTotal = Opt1 + Opt2 + Opt3 + Opt4
'total base options
BaseTotal = Num1 + Num2 + Num3 + Num4
' Tax calculation
Tax = (OptionTotal + BaseTotal) * 0.095
GrandTotal = (BaseTotal + OptionTotal + Tax)
'output to text boxes
TextBox5.Text = FormatNumber(BaseTotal, 2)
TextBox6.Text = FormatNumber(OptionTotal, 2)
TextBox7.Text = FormatNumber(Tax, 2)
TextBox8.Text = FormatNumber(GrandTotal, 2)
End Sub
For Each ctrl As Control In form1.Controls
If ctrl.[GetType]() = GetType(TextBox) Then
DirectCast(ctrl, TextBox).Text = String.Empty
ElseIf ctrl.[GetType]() = GetType(CheckBox) Then
DirectCast(ctrl, CheckBox).Checked = False
End If
Next
***************If I use the following code of course it works, however it would be tedious if there were numerous controls on the page.
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
End Sub

VB.Net save excel file only in program debugging

I got a problem which is not an error in writing data to Excel file from VB.NET.
The code to save data in Excel file is as the following:
Sub WriteToExcel(ByVal dt As DataTable)
Dim excel_app As New Excel.ApplicationClass()
excel_app.Visible = True
Dim workbook As Excel.Workbook = excel_app.Workbooks.Open(Filename:=FileUpload1.PostedFile.FileName)
Dim sheet_name As String = "rptSyncADandITSM"
Dim sheet As Excel.Worksheet = FindSheet(workbook, sheet_name)
sheet.Cells(1, "AF") = "Status"
sheet.Cells(1, "AG") = "Message"
sheet.Range("AF" & 1).Style.VerticalAlignment = VerticalAlign.Top
sheet.Range("AF1").Style.HorizontalAlignment = HorizontalAlign.Center
sheet.Range("AF1").ColumnWidth = 10
sheet.Range("AG1").Style.VerticalAlignment = VerticalAlign.Top
sheet.Range("AG1").Style.HorizontalAlignment = HorizontalAlign.Center
sheet.Range("AG1").ColumnWidth = 15
Dim header_range As Excel.Range = sheet.Range("AF1", "AG1")
header_range.Font.Bold = True
header_range.Font.Color = System.Drawing.ColorTranslator.ToOle(Drawing.Color.Black)
Dim borders As Excel.Borders = header_range.Borders
borders.LineStyle = Excel.XlLineStyle.xlContinuous
borders.Weight = 1.9R
For Each dr As DataRow In dt.Rows
Dim value_range As Excel.Range = sheet.Range("AF" & dr(0).ToString, "AG" & dr(0).ToString)
If Not dr.IsNull(0) Then
sheet.Range("AF" & dr(0).ToString).Style.VerticalAlignment = VerticalAlign.Top
sheet.Range("AF" & dr(0).ToString).Style.HorizontalAlignment = HorizontalAlign.Center
sheet.Range("AF" & dr(0).ToString).ColumnWidth = 10
sheet.Range("AG" & dr(0).ToString).Style.VerticalAlignment = VerticalAlign.Top
sheet.Range("AG" & dr(0).ToString).Style.HorizontalAlignment = HorizontalAlign.Center
sheet.Range("AG" & dr(0).ToString).ColumnWidth = 15
Dim values(0, 1) As String
values(0, 0) = dr(1).ToString
values(0, 1) = dr(2).ToString
value_range.Value2 = values
End If
Dim value_borders As Excel.Borders = value_range.Borders
value_borders.LineStyle = Excel.XlLineStyle.xlContinuous
value_borders.Weight = 2.0R
Next
workbook.Save()
workbook.Close()
'workbook.Close(SaveChanges:=True)
excel_app.Quit()
End Sub
I reference these codes from this
But it only works when i debug the program. In runtime(not debugging) doesn't work to save.

My textbox is not filled with data

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
TextBox3.Text = Now()
Dim com As New SqlCommand
com.CommandType = CommandType.Text
com.CommandText = "select productname ,productid,productdescreption,price from products order by productname "
com.Connection = con
Dim ad As New SqlDataAdapter
Dim ds As New DataSet
ad.SelectCommand = com
ad.Fill(ds)
DropDownList1.DataSource = ds
DropDownList1.DataTextField = "productname"
DropDownList1.DataValueField = "productid"
'Dim ss As Integer
'ss = Convert.ToInt32(DropDownList1.DataValueField)
'DropDownList1.DataValueField = ss
DropDownList1.DataBind()
Dim com2 As New SqlCommand
com2.CommandType = CommandType.Text
com2.CommandText = "select dealername ,dealerid from dealerin order by dealername "
com2.Connection = con
Dim ad2 As New SqlDataAdapter
Dim ds2 As New DataSet
ad2.SelectCommand = com2
ad2.Fill(ds2)
DropDownList2.DataSource = ds2
DropDownList2.DataTextField = "dealername"
DropDownList2.DataValueField = "dealerid"
DropDownList2.DataBind()
'Dim com3 As New SqlCommand
'com3.CommandType = CommandType.Text
'com3.CommandText = "select distinct productname ,productid,productdescreption from products "
'com3.Connection = con
'Dim ad3 As New SqlDataAdapter
'Dim ds3 As New DataSet
'ad2.SelectCommand = com3
'ad2.Fill(ds3)
'DropDownList3.DataSource = ds3
'DropDownList3.DataTextField = "productdescreption"
'DropDownList3.DataValueField = "productid"
'DropDownList3.DataBind()
End If
End Sub
Dim dss As New DataSet
Public Function getproduct_byid(ByVal productid As Integer) As DataSet
Try
Dim com3 As New SqlCommand
com3.CommandType = CommandType.StoredProcedure
com3.CommandText = "getproduct_byid"
com3.Connection = con
'com.Parameters.AddWithValue("#productid", productid)
Dim adapter3 As New SqlDataAdapter(com3)
adapter3.Fill(dss, "product")
Return dss
Catch ex As Exception
Response.Write("error due to " & ex.Message)
End Try
End Function
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Try
getproduct_byid(DropDownList1.SelectedValue)
If dss.Tables("product").Rows.Count = 1 Then
TextBox5.Text = dss.Tables("product").Rows(0).Item("price")
End If
Catch ex As Exception
Response.Write("error due to " & ex.Message)
End Try
End Sub
Protected Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
Try
Dim a As Double
Dim b As Double
a = TextBox4.Text
b = TextBox5.Text
TextBox6.Text = A * b
Catch ex As Exception
Response.Write("error due to " & ex.Message)
End Try
End Sub
It might be your datatable contain more than 1 row ..
Change this
If dss.Tables("product").Rows.Count = 1 Then
To
If dss.Tables("product").Rows.Count > 0 Then

Accessing a button control inside an asp.net Ajax accordion panel

I have a problem, my accordion panel with a dynamically generated accordion panes, with dynamically generated controls like my "btnVoucherProcess" button.
Now I am trying to access my button (btnVoucherProcess) using the "Find control" method as follows:
For i As Int32 = 0 To acAccomodation.Panes.Count - 1
Dim btnVoucherProcess As Button CType(acAccomodation.FindControl("btnVoucherProcess" & i), Button) 'New Button("btnVoucherProcess" & i)
btnVoucherProcess.Text = "Saved " & i
Next
This code throws an error if I run it,the error tells me that my button is null. How do I access my button (btnVoucherProcess) inside an accordion.
Thanks in advance.
===========
here is the entire code
The code is called in page_load
The code that is called in page_load Private Sub emptyDaysAddMode(ByVal duration As Integer)
For i As Integer = 0 To duration - 1
Dim pn As New AjaxControlToolkit.AccordionPane()
pn.ID = "Pane" & i
pn.HeaderContainer.Controls.Add(accomodation(i, "", "", "", txtMarkup.Text, 0, 0, 0, 0, 0, 0))
pn.ContentContainer.Controls.Add(accomodationDetails(i))
acAccomodation.Panes.Add(pn)
'drRow(0) = i + 1
'dtExcel.Rows.Add(drRow)
Next
End Sub
Function accomodation(ByVal i As Int32, ByVal ID As String, ByVal dteDate As String, ByVal strDescription As String, ByVal Markup As Double, ByVal SGL As Int32, ByVal Twin As Int32, ByVal Triple As Int32, ByVal Child As Int32, ByVal Teen As Int32, ByVal ChildOR As Int32) As Table
accomodation = New Table()
Dim myTableRow As New TableRow
myTableRow.Width = Unit.Percentage(100)
Dim dayCell As New TableCell
Dim txtDay As TextBox = New TextBox
txtDay.ID = "txtDate" & i
txtDay.Text = dteDate
If txtDay.Text = "" And txtArrival.Text <> "" Then txtDay.Text = DateAdd("d", i, CType(txtArrival.Text, Date))
txtDay.Width = Unit.Pixel(70)
dayCell.Controls.Add(txtDay)
Dim lblAccID As Label = New Label
lblAccID.ID = "lblAccID" & i
lblAccID.Text = ID
lblAccID.Visible = False
dayCell.Controls.Add(lblAccID)
myTableRow.Cells.Add(dayCell)
Dim hotelRateCell As New TableCell
Dim txtHotelRate As TextBox = New TextBox
txtHotelRate.ID = "txtHotelRate" & i
txtHotelRate.Text = strDescription
txtHotelRate.Width = Unit.Pixel(295)
txtHotelRate.Attributes.Add("onkeyup", "javascript:Complete(this, event," & i & ")")
hotelRateCell.Controls.Add(txtHotelRate)
myTableRow.Cells.Add(hotelRateCell)
Dim markupCell As New TableCell
Dim txtmarkup As TextBox = New TextBox
txtmarkup.ID = "txtMarkup" & i
txtmarkup.Width = Unit.Pixel(35)
txtmarkup.Text = Markup
If txtmarkup.Text = 0 Then txtmarkup.Text = txtQuotationMarkup.Text
txtmarkup.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
markupCell.Controls.Add(txtmarkup)
myTableRow.Cells.Add(markupCell)
Dim nightCell As New TableCell
Dim txtnight As TextBox = New TextBox
txtnight.ID = "txtnight" & i
txtnight.Text = 1
txtnight.Width = Unit.Pixel(25)
txtnight.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
nightCell.Controls.Add(txtnight)
myTableRow.Cells.Add(nightCell)
Dim sglCell As New TableCell
Dim txtSGL As TextBox = New TextBox
txtSGL.ID = "txtSGL" & i
txtSGL.Width = Unit.Pixel(25)
txtSGL.Text = SGL
txtSGL.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
sglCell.Controls.Add(txtSGL)
myTableRow.Cells.Add(sglCell)
Dim DBLCell As New TableCell
Dim txtDBL As TextBox = New TextBox
txtDBL.ID = "txtDBL" & i
txtDBL.Width = Unit.Pixel(25)
txtDBL.Text = Twin
txtDBL.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
DBLCell.Controls.Add(txtDBL)
myTableRow.Cells.Add(DBLCell)
Dim trpCell As New TableCell
Dim txtTRP As TextBox = New TextBox
txtTRP.ID = "txtTRP" & i
txtTRP.Width = Unit.Pixel(25)
txtTRP.Text = Triple
txtTRP.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
trpCell.Controls.Add(txtTRP)
myTableRow.Cells.Add(trpCell)
Dim chdCell As New TableCell
Dim txtCHD As TextBox = New TextBox
txtCHD.ID = "txtCHD" & i
txtCHD.Width = Unit.Pixel(25)
txtCHD.Text = Child
txtCHD.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
chdCell.Controls.Add(txtCHD)
myTableRow.Cells.Add(chdCell)
Dim tnCell As New TableCell
Dim txtTN As TextBox = New TextBox
txtTN.ID = "txtTN" & i
txtTN.Width = Unit.Pixel(25)
txtTN.Text = Teen
txtTN.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
tnCell.Controls.Add(txtTN)
myTableRow.Cells.Add(tnCell)
Dim childOWRCell As New TableCell
Dim txtChildOWR As TextBox = New TextBox
txtChildOWR.ID = "txtchildOWR" & i
txtChildOWR.Width = Unit.Pixel(25)
txtChildOWR.Text = ChildOR
txtChildOWR.Attributes.Add("onchange", "javascript:accomodationCalc(" & i & ")")
childOWRCell.Controls.Add(txtChildOWR)
myTableRow.Cells.Add(childOWRCell)
Dim CostCell As New TableCell
Dim txtCost As TextBox = New TextBox
txtCost.ID = "txtCost" & i
txtCost.Width = Unit.Pixel(55)
txtCost.Enabled = False
CostCell.Controls.Add(txtCost)
myTableRow.Cells.Add(CostCell)
Dim SaleCell As New TableCell
Dim txtSale As TextBox = New TextBox
txtSale.ID = "txtSale" & i
txtSale.Width = Unit.Pixel(55)
txtSale.Enabled = False
SaleCell.Controls.Add(txtSale)
myTableRow.Cells.Add(SaleCell)
Dim ProfitCell As New TableCell
Dim txtProfit As TextBox = New TextBox
txtProfit.ID = "txtProfit" & i
txtProfit.Width = Unit.Pixel(60)
txtProfit.Enabled = False
ProfitCell.Controls.Add(txtProfit)
myTableRow.Cells.Add(ProfitCell)
Dim deleteCell As New TableCell
Dim chkAccDelete As CheckBox = New CheckBox
chkAccDelete.ID = "chkAccDelete" & i
chkAccDelete.Width = Unit.Pixel(60)
deleteCell.Controls.Add(chkAccDelete)
myTableRow.Cells.Add(deleteCell)
accomodation.Rows.Add(myTableRow)
Return accomodation
End Function
Function accomodationDetails(ByVal i As Int32) As Table
accomodationDetails = New Table()
accomodationDetails.BorderColor = Color.Black
accomodationDetails.BorderStyle = BorderStyle.Solid
'------1st Row
Dim tableRow1 As New TableRow
Dim mycell1 As New TableCell
mycell1.Text = "Description"
mycell1.BackColor = Color.Gray
'Dim tb As TextBox = New TextBox
tableRow1.Cells.Add(mycell1)
Dim mycell2 As New TableCell
mycell2.Text = "Single"
mycell2.BackColor = Color.Gray
tableRow1.Cells.Add(mycell2)
Dim mycell3 As New TableCell
mycell3.Text = "Double"
mycell3.BackColor = Color.Gray
tableRow1.Cells.Add(mycell3)
Dim mycell4 As New TableCell
mycell4.Text = "Triple"
mycell4.BackColor = Color.Gray
tableRow1.Cells.Add(mycell4)
Dim mycell5 As New TableCell
mycell5.Text = "Child"
mycell5.BackColor = Color.Gray
tableRow1.Cells.Add(mycell5)
Dim mycell6 As New TableCell
mycell6.Text = "Teen"
mycell6.BackColor = Color.Gray
tableRow1.Cells.Add(mycell6)
Dim mycell7 As New TableCell
mycell7.Text = "Child(OR)"
mycell7.BackColor = Color.Gray
tableRow1.Cells.Add(mycell7)
accomodationDetails.Rows.Add(tableRow1)
'------2nd Row
Dim tableRow2 As New TableRow
Dim mycell1R2 As New TableCell
mycell1R2.Text = "Cost"
tableRow2.Cells.Add(mycell1R2)
Dim mycell2R2 As New TableCell
Dim txtSingle As TextBox = New TextBox
txtSingle.ID = "txtSingle" & i
txtSingle.Width = Unit.Pixel(60)
mycell2R2.Controls.Add(txtSingle)
tableRow2.Cells.Add(mycell2R2)
Dim mycell3R2 As New TableCell
Dim txtDouble As TextBox = New TextBox
txtDouble.ID = "txtDouble" & i
txtDouble.Width = Unit.Pixel(60)
mycell3R2.Controls.Add(txtDouble)
tableRow2.Cells.Add(mycell3R2)
accomodationDetails.Rows.Add(tableRow2)
Dim mycell4R2 As New TableCell
Dim txtTriple As TextBox = New TextBox
txtTriple.ID = "txtTriple" & i
txtTriple.Width = Unit.Pixel(60)
mycell4R2.Controls.Add(txtTriple)
tableRow2.Cells.Add(mycell4R2)
accomodationDetails.Rows.Add(tableRow2)
Dim mycell5R2 As New TableCell
Dim txtChild As TextBox = New TextBox
txtChild.ID = "txtChild" & i
txtChild.Width = Unit.Pixel(60)
mycell5R2.Controls.Add(txtChild)
tableRow2.Cells.Add(mycell5R2)
accomodationDetails.Rows.Add(tableRow2)
Dim mycell6R2 As New TableCell
Dim txtTeen As TextBox = New TextBox
txtTeen.ID = "txtTeen" & i
txtTeen.Width = Unit.Pixel(60)
mycell6R2.Controls.Add(txtTeen)
tableRow2.Cells.Add(mycell6R2)
Dim mycell7R2 As New TableCell
Dim txtChildOR As TextBox = New TextBox
txtChildOR.ID = "txtChildOR" & i
txtChildOR.Width = Unit.Pixel(60)
mycell7R2.Controls.Add(txtChildOR)
tableRow2.Cells.Add(mycell7R2)
accomodationDetails.Rows.Add(tableRow2)
'------3rd Row
Dim tableRow3 As New TableRow
Dim mycell1R3 As New TableCell
mycell1R3.Text = "Sales"
tableRow3.Cells.Add(mycell1R3)
Dim mycell2R3 As New TableCell
Dim txtSingleSale As TextBox = New TextBox
txtSingleSale.ID = "txtSingleSale" & i
txtSingleSale.Width = Unit.Pixel(60)
mycell2R3.Controls.Add(txtSingleSale)
tableRow3.Cells.Add(mycell2R3)
Dim mycell3R3 As New TableCell
Dim txtDoubleSale As TextBox = New TextBox
txtDoubleSale.ID = "txtDoubleSale" & i
txtDoubleSale.Width = Unit.Pixel(60)
mycell3R3.Controls.Add(txtDoubleSale)
tableRow3.Cells.Add(mycell3R3)
Dim mycell4R3 As New TableCell
Dim txtTripleSale As TextBox = New TextBox
txtTripleSale.ID = "txtTripleSale" & i
txtTripleSale.Width = Unit.Pixel(60)
mycell4R3.Controls.Add(txtTripleSale)
tableRow3.Cells.Add(mycell4R3)
Dim mycell5R3 As New TableCell
Dim txtChildSale As TextBox = New TextBox
txtChildSale.ID = "txtChildSale" & i
txtChildSale.Width = Unit.Pixel(60)
mycell5R3.Controls.Add(txtChildSale)
tableRow3.Cells.Add(mycell5R3)
Dim mycell6R3 As New TableCell
Dim txtTeenSale As TextBox = New TextBox
txtTeenSale.ID = "txtTeenSale" & i
txtTeenSale.Width = Unit.Pixel(60)
mycell6R3.Controls.Add(txtTeenSale)
tableRow3.Cells.Add(mycell6R3)
Dim mycell7R3 As New TableCell
Dim txtChildORSale As TextBox = New TextBox
txtChildORSale.ID = "txtChildORSale" & i
txtChildORSale.Width = Unit.Pixel(60)
mycell7R3.Controls.Add(txtChildORSale)
tableRow3.Cells.Add(mycell7R3)
accomodationDetails.Rows.Add(tableRow3)
'-----4th Row
Dim tableRow4 As New TableRow
Dim mycell1R4 As New TableCell
mycell1R4.Text = "Voucher remarks"
tableRow4.Cells.Add(mycell1R4)
Dim mycell2R4 As New TableCell
mycell2R4.ColumnSpan = "6"
Dim txtVoucherRemarks As TextBox = New TextBox
txtVoucherRemarks.ID = "txtVoucherRemarks" & i
txtVoucherRemarks.Width = Unit.Pixel(420)
txtVoucherRemarks.TextMode = TextBoxMode.MultiLine
mycell2R4.Controls.Add(txtVoucherRemarks)
tableRow4.Cells.Add(mycell2R4)
accomodationDetails.Rows.Add(tableRow4)
'------5th Row
Dim tableRow5 As New TableRow
Dim mycell1R5 As New TableCell
Dim chkPark As New CheckBox
chkPark.ID = "chkPark" & i
chkPark.Text = "Include park fees."
mycell1R5.Text = ""
mycell1R5.Controls.Add(chkPark)
tableRow5.Cells.Add(mycell1R5)
Dim mycell2R5 As New TableCell
mycell2R5.ColumnSpan = "2"
Dim btnVoucherProcess As Button = New Button
btnVoucherProcess.ID = "btnVoucherProcess" & i
btnVoucherProcess.Width = Unit.Pixel(120)
btnVoucherProcess.Text = "Book"
mycell2R5.Controls.Add(btnVoucherProcess)
tableRow5.Cells.Add(mycell2R5)
Dim mycell3R5 As New TableCell
mycell3R5.ColumnSpan = "2"
Dim btnVoucherCancel As Button = New Button
btnVoucherCancel.ID = "btnVoucherCancel" & i
btnVoucherCancel.Width = Unit.Pixel(120)
btnVoucherCancel.Text = "Cancel voucher"
mycell3R5.Controls.Add(btnVoucherCancel)
tableRow5.Cells.Add(mycell3R5)
Dim mycell4R5 As New TableCell
mycell4R5.ColumnSpan = "2"
Dim btnVoucherPrint As Button = New Button
btnVoucherPrint.ID = "btnVoucherPrint" & i
btnVoucherPrint.Width = Unit.Pixel(120)
btnVoucherPrint.Text = "Print voucher"
mycell4R5.Controls.Add(btnVoucherPrint)
tableRow5.Cells.Add(mycell4R5)
accomodationDetails.Rows.Add(tableRow5)
Return accomodationDetails
End Function
This following code is triggered by the button outside the accordion
Protected Sub btnSaveAccomodation_Click(sender As Object, e As System.EventArgs) Handles btnSaveAccomodation.Click
For i As Int32 = 0 To acAccomodation.Panes.Count - 1
'For Each i As In Me.cdTransport.Items
' Dim btnVoucherProcess As Button = CType(acAccomodation.FindControl("btnVoucherProcess" & i), Button) 'New Button("btnVoucherProcess" & i)
Dim controlName As String = "btnVoucherProcess" & i
Dim btnVoucherProcess As Button = CType(acAccomodation.Panes(i).ContentContainer.FindControl("btnVoucherProcess" & i), Button)
btnVoucherProcess.Text = "Saved " & i
'Dim cboDay As DropDownList = CType(i.FindControl("cboDay"), DropDownList)
Next
End Sub
If you are dynamically rendering the controls, and later, you are trying to access the dynamic controls through an event handler, e.g. a button's Click method implementation, you'll get nothing.
For finding always the dynamically generated controls, you should always create them in your Page_Load event. Always. So that the event handler that tries to access your dynamic controls will find them and, I can't explain why but, this dynamic controls will contain the values that were entered by the user on client side.

Resources