I have an app by vb for taking a list of doneators in Dvg and have about 17 forum and local mssql db and using if not is dbnull expression and by pressing the button some calculation happened and the answer appears in labels on the fourm.. But A strange problem happened when I run this app by the visual studio 2017 it run perfectly and there is no error.. But when converting it to exe file and setup it the following error appear when pressing this button " Argument 'expression' cannot be converted to type 'DBNull'
" although it's not appear when run it with visual studio.. What could the problem be..?
here is the code but i don't think the problem in it because it works fine in visual studio
its long code so i will put a part of it and the rest is repeated for 12 months and 10 yearsthis is pic of the error
If Form1.ComboBox1.Text = "2018" Then
' total kfalat
If TextBox1.Text = "1" Then
Form5.total.Text = Form1.Table1DataGridView.Rows.Count - 1
Dim HoN As Integer = 0
' total done
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "1" Then
HoN = HoN + 1
End If
End If
End If
End If
Next
Form5.done.Text = HoN.ToString
'undone
Form5.notdone.Text = Val(Form5.total.Text) - Val(Form5.done.Text)
'asbab 3adam alta7seel
'lm yarod
Dim HoN11 As Integer = 0
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "لم يرد" Then
HoN11 = HoN11 + 1
End If
End If
End If
End If
Next
Form5.Label69.Text = HoN11.ToString
'lmo2agal
Dim HoN12 As Integer = 0
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "مؤجل" Then
HoN12 = HoN12 + 1
End If
End If
End If
End If
Next
Form5.Label67.Text = HoN12.ToString
'سيحضر
Dim HoN13 As Integer = 0
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "سيحضر " Then
HoN13 = HoN13 + 1
End If
End If
End If
End If
Next
Form5.Label65.Text = HoN13.ToString
Dim HoN10 As Integer = 0
Dim money As Integer = 0
' astmarat gdeda
For Each gvRow As DataGridViewRow In Form1.Table1DataGridView.Rows
If Not IsDBNull(gvRow.Cells(8).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(8).Value) AndAlso Val(gvRow.Cells(8).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(15).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(15).Value > 0 Then
HoN10 = HoN10 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
money = money + Val(gvRow.Cells(15).Value)
End If
End If
End If
End If
Next
Form5.Label59.Text = HoN10.ToString
Form5.Label58.Text = money.ToString
Dim orphensmoney1 As Integer = 0
Dim HoN1 As Integer = 0
Dim familiesmoney1 As Integer = 0
Dim HoN2 As Integer = 0
Dim sicksmoney1 As Integer = 0
Dim HoN3 As Integer = 0
Dim studentsmoney1 As Integer = 0
Dim HoN4 As Integer = 0
' alkafalat almotwagda belf3l
For Each gvRow As DataGridViewRow In Form1.Table1DataGridView.Rows
If Not IsDBNull(gvRow.Cells(19).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(19).Value = True Then
HoN1 = HoN1 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
orphensmoney1 = orphensmoney1 + Val(gvRow.Cells(23).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(20).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(20).Value = True Then
HoN2 = HoN2 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
familiesmoney1 = familiesmoney1 + Val(gvRow.Cells(24).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(21).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(21).Value = True Then
HoN3 = HoN3 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
sicksmoney1 = sicksmoney1 + Val(gvRow.Cells(25).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(22).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(22).Value = True Then
HoN4 = HoN4 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
studentsmoney1 = studentsmoney1 + Val(gvRow.Cells(26).Value)
End If
End If
Next
Form5.Label11.Text = HoN1.ToString
Form5.Label10.Text = orphensmoney1.ToString
Form5.Label14.Text = HoN2.ToString
Form5.Label13.Text = familiesmoney1.ToString
Form5.Label17.Text = HoN3.ToString
Form5.Label16.Text = sicksmoney1.ToString
Form5.Label20.Text = HoN4.ToString
Form5.Label19.Text = studentsmoney1.ToString
Form5.Label8.Text = (Val(HoN1) + Val(HoN2) + Val(HoN3) + Val(HoN4)).ToString
Form5.Label9.Text = (Val(orphensmoney1) + Val(familiesmoney1) + Val(sicksmoney1) + Val(studentsmoney1)).ToString
Dim HoN5 As Integer = 0
Dim ORPHENS As Integer = 0
Dim HoN6 As Integer = 0
Dim families As Integer = 0
Dim HoN7 As Integer = 0
Dim sicks As Integer = 0
Dim HoN8 As Integer = 0
Dim students As Integer = 0
' almo7asal fe kol band
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(14).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(14).Value > 0 Then
HoN5 = HoN5 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
ORPHENS = ORPHENS + Val(gvRow.Cells(14).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(16).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(16).Value > 0 Then
HoN6 = HoN6 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
families = families + Val(gvRow.Cells(16).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(18).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(18).Value > 0 Then
HoN7 = HoN7 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
sicks = sicks + Val(gvRow.Cells(18).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(20).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(20).Value > 0 Then
HoN8 = HoN8 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
students = students + Val(gvRow.Cells(20).Value)
End If
End If
End If
End If
Next
Form5.Label32.Text = HoN5.ToString
Form5.Label31.Text = ORPHENS.ToString
Form5.Label29.Text = HoN6.ToString
Form5.Label28.Text = families.ToString
Form5.Label26.Text = HoN7.ToString
Form5.Label25.Text = sicks.ToString
Form5.Label23.Text = HoN8.ToString
Form5.Label22.Text = students.ToString
Form5.Label35.Text = Val(HoN8.ToString) + Val(HoN7.ToString) + Val(HoN6.ToString) + Val(HoN5.ToString)
Form5.Label34.Text = Val(ORPHENS.ToString) + Val(families.ToString) + Val(sicks.ToString) + Val(students.ToString)
Form5.Label53.Text = Val(Form5.Label8.Text) - Val(Form5.Label35.Text)
Form5.Label52.Text = Val(Form5.Label9.Text) - Val(Form5.Label34.Text)
Form5.Label50.Text = Val(Form5.Label11.Text) - Val(Form5.Label32.Text)
Form5.Label49.Text = Val(Form5.Label10.Text) - Val(Form5.Label31.Text)
Form5.Label47.Text = Val(Form5.Label14.Text) - Val(Form5.Label29.Text)
Form5.Label46.Text = Val(Form5.Label13.Text) - Val(Form5.Label28.Text)
Form5.Label44.Text = Val(Form5.Label17.Text) - Val(Form5.Label26.Text)
Form5.Label43.Text = Val(Form5.Label16.Text) - Val(Form5.Label25.Text)
Form5.Label41.Text = Val(Form5.Label20.Text) - Val(Form5.Label23.Text)
Form5.Label40.Text = Val(Form5.Label19.Text) - Val(Form5.Label22.Text)
End If
Private Sub Arr(ByVal arrRad() As RadioButton, ByVal arrLbl() As Label)
Dim result As Integer = 0
Dim temp As Integer = 0
'arrRad is my control array Radiobutton, arrLbl is my control array Label
'I have 15 Radiobutton and 3 Label
For i As Integer = 0 To arrRad.Length - 1 Step 5
If arrRad(i).Checked = True Then
temp = arrRad(i).Text.Substring(0, 1)
ElseIf arrRad(i + 1).Checked = True Then
temp = arrRad(i + 1).Text.Substring(0, 1)
ElseIf arrRad(i + 2).Checked = True Then
temp = arrRad(i + 2).Text.Substring(0, 1)
ElseIf arrRad(i + 3).Checked = True Then
temp = arrRad(i + 3).Text.Substring(0, 1)
ElseIf arrRad(i + 4).Checked = True Then
temp = arrRad(i + 4).Text.Substring(0, 1)
Else
temp = 0
End If
result += temp
Next
txtKetQua.Text = result.ToString()
End Sub
I want to show lblError if that row radiobutton is unchecked, but I don't know how to show it
P/s: Sorry for my bad English
You can do it in a very shorter way using LInQ Extension .Any():
lblError.Visible = Not arrRad.Any(Function(rb) rb.Ckecked)
I have a problem on saving the data that I'm inputting. I have to click the button twice for it to fire up.
I'm trying to add the employee's group details. When I first click the Add button the group details that I'm adding will be successfully added but when i try to add another one again it will not be saved and I have to click the button again for it to be saved or for the button to function.
Here's the codes when I click the Add button
If ValidateGroup() = "" Then
taskoption = Request.QueryString("opt")
If taskoption = "opt_edit" Then
SaveGroup()
disp_Details()
Loadgv()
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
ElseIf taskoption = "opt_add" Then
disp_Blank()
Me.btnSave.Enabled = True
Me.btnUpdate.Enabled = False
ElseIf taskoption = "opt_ae" Then
SaveGroup()
disp_Details()
gvGroup.Visible = True
tblGroup.Visible = True
id_tm1.Visible = True
tblAddGrp.Visible = True
trgd.Visible = False
disp_Group()
Loadgv()
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
End If
Else
Me.MessageBox("alert('Please complete the following: \n" + ValidateGroup() + "\n')")
End If
here's my code in Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
userid = getUserid(SessionHandler.UserID, User.Identity.Name.ToUpper(), username)
bol_Admin = isAdmin(userid)
bol_GlobalHR = isGlobalHR(userid)
bol_RegionalHR = isRegionalHR(userid)
bol_LocalHR = isLocalHR(userid)
userEntity = getEntity(userid)
userLocation = getLocation(userid)
userRegion = getRegion(userid)
If KnownUser(userid) Then
If bol_Admin Or bol_GlobalHR Or bol_RegionalHR Or bol_LocalHR Then
If Not Page.IsPostBack Then
Dim win_id As String = User.Identity.Name
loadSetup()
If bol_Admin Or bol_GlobalHR Then
access = "GLOBAL"
ehr_utils.fillDDL("SELECT REGION FROM REGION_TBL ORDER BY REGION", ddl_Region, "REGION", "REGION")
ehr_utils.fillDDL("SELECT COUNTRY FROM COUNTRY_TBL ORDER BY COUNTRY", ddl_Country, "COUNTRY", "COUNTRY")
ehr_utils.fillDDL("SELECT ENTITY FROM ENTITY_TBL ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT LOCATION FROM LOCATION_TBL ORDER BY LOCATION", ddl_Location, "LOCATION", "LOCATION")
ehr_utils.fillDDL("SELECT DISTINCT C_PERIOD FROM PERIODSETUP_TBL", Me.ddl_period, "C_PERIOD", "C_PERIOD")
ehr_utils.fillDDL("SELECT SUBLOOKUP_NAME FROM SUBLOOKUP_TBL WHERE LOOKUP_NAME = 'YEAR'", Me.ddl_year, "SUBLOOKUP_NAME", "SUBLOOKUP_NAME")
ElseIf bol_RegionalHR Then
access = "REGIONAL"
ehr_utils.fillDDL("SELECT REGION FROM REGION_TBL where region = '" & userRegion & "' ORDER BY REGION", ddl_Region, "REGION", "REGION")
ehr_utils.fillDDL("SELECT COUNTRY FROM COUNTRY_TBL where region = '" & userRegion & "' ORDER BY COUNTRY", ddl_Country, "COUNTRY", "COUNTRY")
ehr_utils.fillDDL("SELECT ENTITY FROM ENTITY_TBL where region = '" & userRegion & "' ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT LOCATION FROM LOCATION_TBL where region = '" & userRegion & "' ORDER BY LOCATION", ddl_Location, "LOCATION", "LOCATION")
ehr_utils.fillDDL("SELECT DISTINCT C_PERIOD FROM PERIODSETUP_TBL", Me.ddl_period, "C_PERIOD", "C_PERIOD")
ehr_utils.fillDDL("SELECT SUBLOOKUP_NAME FROM SUBLOOKUP_TBL WHERE LOOKUP_NAME = 'YEAR'", Me.ddl_year, "SUBLOOKUP_NAME", "SUBLOOKUP_NAME")
ElseIf bol_LocalHR Then
access = "LOCAL"
Dim emp_id As String = Request.QueryString("emp_id")
selectedEmpEntity = getValueString("SELECT entity FROM EMP_MASTERTBL WHERE MASTERID = '" & emp_id & "'")
ehr_utils.fillDDL("SELECT REGION FROM REGION_TBL where region = '" & userRegion & "' ORDER BY REGION", ddl_Region, "REGION", "REGION")
ehr_utils.fillDDL("SELECT COUNTRY FROM COUNTRY_TBL where region = '" & userRegion & "' ORDER BY COUNTRY", ddl_Country, "COUNTRY", "COUNTRY")
'ehr_utils.fillDDL("SELECT ENTITY FROM ENTITY_TBL where entity = '" & userEntity & "' ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT ENTITY FROM LOCALHR_TBL WHERE USERID = '" & userid & "' ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT LOCATION FROM LOCATION_TBL where entity = '" & selectedEmpEntity & "' ORDER BY LOCATION", ddl_Location, "LOCATION", "LOCATION")
ehr_utils.fillDDL("SELECT DISTINCT C_PERIOD FROM PERIODSETUP_TBL", Me.ddl_period, "C_PERIOD", "C_PERIOD")
ehr_utils.fillDDL("SELECT SUBLOOKUP_NAME FROM SUBLOOKUP_TBL WHERE LOOKUP_NAME = 'YEAR'", Me.ddl_year, "SUBLOOKUP_NAME", "SUBLOOKUP_NAME")
End If
taskoption = Request.QueryString("opt")
updateBtnRmndr.Visible = False
If taskoption = "opt_edit" Then
gvGroup.Columns(9).Visible = True
gvGroup.Columns(10).Visible = True
disp_Details()
Loadgv()
loadSetup()
gvGroup.Visible = True
tblAddGrp.Visible = True
trgd.Visible = False
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
Me.ddl_BusinessUnit.Enabled = True
Me.ddl_SubClassification.Enabled = True
ehr_utils.fillDDL("SELECT BUSINESS_UNIT FROM BUSINESS_UNIT_TBL ORDER BY BUSINESS_UNIT", Me.ddl_BusinessUnit, "BUSINESS_UNIT", "BUSINESS_UNIT")
'Check if the user has access to use the UPDATE ALL function
hasAccess = CheckRecord("SELECT * FROM ACCESSLIST_TBL WHERE MODULE_ID = '1' AND ACCESS = '" & access & "'")
If hasAccess Then 'allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = True
btnUpdateHistoryRecord.Enabled = True
Session("originalEmpNo") = lblval_Empno.Text
updateBtnRmndr.Visible = True
Else ' Not allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = False
btnUpdateHistoryRecord.Enabled = False
End If
ElseIf taskoption = "opt_ae" Then
gvGroup.Columns(9).Visible = False
gvGroup.Columns(10).Visible = False
gvGroup.Columns(7).Visible = False
trgd.Visible = True
tblAddGrp.Visible = True
Loadgv()
disp_Details()
disp_Group()
gvGroup.Visible = False
tblGroup.Visible = False
id_tm1.Visible = False
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
'Check if the user has access to use the UPDATE ALL function
hasAccess = CheckRecord("SELECT * FROM ACCESSLIST_TBL WHERE MODULE_ID = '1' AND ACCESS = '" & access & "'")
If hasAccess Then 'allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = True
btnUpdateHistoryRecord.Enabled = True
updateBtnRmndr.Visible = True
Session("originalEmpNo") = lblval_Empno.Text
Else ' Not allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = False
btnUpdateHistoryRecord.Enabled = False
End If
Me.ddl_BusinessUnit.Enabled = True
Me.ddl_SubClassification.Enabled = True
ehr_utils.fillDDL("SELECT BUSINESS_UNIT FROM BUSINESS_UNIT_TBL ORDER BY BUSINESS_UNIT", Me.ddl_BusinessUnit, "BUSINESS_UNIT", "BUSINESS_UNIT")
ElseIf taskoption = "opt_add" Then
tblAddGrp.Visible = False
tblGroup.Visible = False
id_tm1.Visible = False
trgd.Visible = False
gvGroup.Visible = False
disp_Blank()
loadSetup()
Me.btnSave.Enabled = True
Me.btnUpdate.Enabled = False
'hide the UPDATE ALL function
btnUpdateHistoryRecord.Visible = False
btnUpdateHistoryRecord.Enabled = False
End If
div_birthDate.InnerText = txtBdate.Text
div_entryDate.InnerText = txtEdate.Text
Else
Dim scriptString As New StringBuilder
scriptString.Append("<script language=JavaScript>")
scriptString.Append("alert('You are not allowed to view this page.');")
scriptString.Append("window.location = 'eHR_Main.aspx';")
scriptString.Append("</script>")
If Not ClientScript.IsStartupScriptRegistered("Startup") Then
ClientScript.RegisterStartupScript(GetType(Page), "Startup", scriptString.ToString())
End If
End If
Else
MessageBox("alert('You're not allowed to view this page.');window.location='eHR_Main.aspx';")
End If
End If
End Sub
How to refresh the GridView in onSelectIndexChange of a drop down ?
I want the grid to be refreshed or cleared on every index change
and when the ddlist.selectvalue=0 then a pop up comes saying Please select valid option and then the grid hides.
I am using this code:
Protected Sub ddllist_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddllist.SelectedIndexChanged
If ddllist.SelectedValue = 1 Then
tdtype.InnerHtml = "Leas ID"
btnSave.Enabled = True
trtype.Visible = True
ElseIf (ddllist.SelectedValue = 0) Then
btnSave.Enabled = False
trtype.Visible = False
' Gridconten.DataSource = ""
'Gridconten.DataBind()
'Page_Load(sender, e)
Gridconten.DataSource = Nothing
Gridconten.DataBind()
Else
btnSave.Enabled = True
tdtype.InnerHtml = "Vendor ID"
trtype.Visible = True
End If
End Sub
ok i have got it after some try i am using this !!
basically i am binding it with no data and hiding the grid on index
change
Protected Sub ddllist_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddllist.SelectedIndexChanged
If ddllist.SelectedValue = 1 Then
Label2.Text = ""
tdtype.InnerHtml = "Leas ID"
btnSave.Enabled = True
trtype.Visible = True
Gridconten.DataSource = Nothing
Gridconten.DataBind()
Gridconten.Visible = False
Gridconten.Columns(0).HeaderText = "Lease ID"
ElseIf (ddllist.SelectedValue = 0) Then
btnSave.Enabled = False
trtype.Visible = False
Label2.Text = ""
' Gridconten.DataSource = ""
'Gridconten.DataBind()
'Page_Load(sender, e)
Gridconten.DataSource = Nothing
Gridconten.DataBind()
Gridconten.Visible = False
Else
Label2.Text = ""
btnSave.Enabled = True
tdtype.InnerHtml = "Vendor ID"
trtype.Visible = True
Gridconten.DataSource = Nothing
Gridconten.DataBind()
Gridconten.Visible = False
Gridconten.Columns(0).HeaderText = "Vendor ID"
End If
End Sub
I have an issue with a dynamically created table within my asp form.
To control the page and create the table, the user selects a date range and clicks a Refresh button.
The table creates after being populated in the code behind, but duplicates,
i.e. 11 rows should populate, but after row 11, rows 12 - 22 are duplicates of 1 - 11.
Interestingly, when clicking a button (created by the code behind, dynamically) the page posts back with the table being as it should rows 1 - 11 and no more. I have replicated the code below in my Page_Load sub.
Please advise, thanks in advance;
Protected Sub Refresh_Click(sender As Object, e As EventArgs)
'/*** CREATES CONNECTION STRING AND OPENS CONNECTION TO DB ***\'
Dim cn As New OleDbConnection
cn.ConnectionString = [String]
cn.Open()
'/*** CREATES DateFormat FOR PLACEMENT WITHIN THE SQL ***\'
Dim dtform As String
dtform = "dd-MMM-yyyy"
'/*** DECLARES AND FINDS FROM & TO DATE FOR SQL STATEMENT ***\'
Dim from As Date
from = Frmdt.Text
Dim todat As Date
todat = Todt.Text
'/*** EXECUTES SQL & CREATES RECORDSET WITH RecordCount ***\'
Dim rs As New ADODB.Recordset()
Dim x As Integer
With rs
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
.CursorType = ADODB.CursorTypeEnum.adOpenStatic
.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
.Open("SELECT * FROM DB", cn.ConnectionString)
x = rs.RecordCount
End With
'/*** DECLARES & FILLS DataAdapter, DataSet & DataTable ***\'
Dim da As New OleDbDataAdapter()
Dim ds As New DataSet()
da.Fill(ds, rs, "[Field Headers]")
Dim dt As DataTable = ds.Tables("[Field Headers]")
'/*** DECLARES ROW COUNTER TO TRACK NUMBER OF ROWS ADDED TO ASP:TABLE ***\'
Dim rwcntr As Integer
'/*** DECLARES ROW COUNTER TO EXTRACT DATA FROM DataTable ***\'
Dim i As Integer
rwcntr = 1
'/*** BEGINS LOOP OF DataTable & CREATES ASP:TABLE, ENDING WHEN ROW COUNTER REACHES RecordCount MINUS 1 ***\'
For i = 0 To x - 1 Step +1
Dim td 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 td8 As New TableCell()
Dim td9 As New TableCell()
Dim td10 As New TableCell()
Dim td11 As New TableCell()
Dim td12 As New TableCell()
Dim td13 As New TableCell()
Dim tr As New TableRow()
td.Text = dt.Rows(i)("[Field Header1]").ToString()
td.Font.Name = "Calibri"
td.BackColor = ColorTranslator.FromHtml("#cccccc")
td.ForeColor = Color.Black
td.Font.Size = 8
td.BorderStyle = WebControls.BorderStyle.Inset
td.BorderColor = Color.Black
td.BorderWidth = 1.5
td.EnableViewState = True
td.HorizontalAlign = WebControls.HorizontalAlign.Center
td.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td)
td2.Text = dt.Rows(i)("[Field Header2]").ToString()
td2.Font.Name = "Calibri"
td2.BackColor = ColorTranslator.FromHtml("#cccccc")
td2.ForeColor = Color.Black
td.BorderWidth = 1.5
td2.Font.Size = 8
td2.BorderStyle = WebControls.BorderStyle.Inset
td2.BorderColor = Color.Black
td2.BorderWidth = 1.5
td2.EnableViewState = True
td2.HorizontalAlign = WebControls.HorizontalAlign.Center
td2.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td2)
td3.Text = dt.Rows(i)("[Field Header3]").ToString()
td3.Font.Name = "Calibri"
td3.BackColor = ColorTranslator.FromHtml("#cccccc")
td3.ForeColor = Color.Black
td3.BorderWidth = 1.5
td3.Font.Size = 8
td3.BorderStyle = WebControls.BorderStyle.Inset
td3.BorderColor = Color.Black
td.BorderWidth = 1.5
td3.EnableViewState = True
td3.HorizontalAlign = WebControls.HorizontalAlign.Center
td3.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td3)
td4.Text = dt.Rows(i)("[Field Header4]").ToString()
td4.Font.Name = "Calibri"
td4.BackColor = ColorTranslator.FromHtml("#cccccc")
td4.ForeColor = Color.Black
td4.Font.Size = 8
td4.BorderStyle = WebControls.BorderStyle.Inset
td4.BorderColor = Color.Black
td4.BorderWidth = 1.5
td4.EnableViewState = True
td4.HorizontalAlign = WebControls.HorizontalAlign.Center
td4.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td4)
td5.Text = dt.Rows(i)("[Field Header5]").ToString()
td5.Font.Name = "Calibri"
td5.BackColor = ColorTranslator.FromHtml("#cccccc")
td5.ForeColor = Color.Black
td5.Font.Size = 8
td5.BorderStyle = WebControls.BorderStyle.Inset
td5.BorderColor = Color.Black
td5.BorderWidth = 1.5
td5.EnableViewState = True
td5.HorizontalAlign = WebControls.HorizontalAlign.Center
td5.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td5)
td6.Text = dt.Rows(i)("[Field Header6]").ToString()
td6.Font.Name = "Calibri"
td6.BackColor = ColorTranslator.FromHtml("#cccccc")
td6.ForeColor = Color.Black
td6.Font.Size = 8
td6.BorderStyle = WebControls.BorderStyle.Inset
td6.BorderColor = Color.Black
td6.BorderWidth = 1.5
td6.EnableViewState = True
td6.HorizontalAlign = WebControls.HorizontalAlign.Center
td6.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td6)
td7.Text = dt.Rows(i)("[Field Header7]").ToString()
td7.Font.Name = "Calibri"
td7.BackColor = ColorTranslator.FromHtml("#cccccc")
td7.ForeColor = Color.Black
td7.Font.Size = 8
td7.BorderStyle = WebControls.BorderStyle.Inset
td7.BorderColor = Color.Black
td7.BorderWidth = 1.5
td7.EnableViewState = True
td7.HorizontalAlign = WebControls.HorizontalAlign.Center
td7.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td7)
td8.Text = dt.Rows(i)("[Field Header8]").ToString()
td8.Font.Name = "Calibri"
td8.BackColor = ColorTranslator.FromHtml("#cccccc")
td8.ForeColor = Color.Black
td8.Font.Size = 8
td8.BorderStyle = WebControls.BorderStyle.Inset
td8.BorderColor = Color.Black
td8.BorderWidth = 1.5
td8.EnableViewState = True
td8.HorizontalAlign = WebControls.HorizontalAlign.Center
td8.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td8)
td9.Text = dt.Rows(i)("[Field Header9]").ToString()
td9.Font.Name = "Calibri"
td9.BackColor = ColorTranslator.FromHtml("#cccccc")
td9.ForeColor = Color.Black
td9.Font.Size = 8
td9.BorderStyle = WebControls.BorderStyle.Inset
td9.BorderColor = Color.Black
td9.BorderWidth = 1.5
td9.Width = 25
td9.EnableViewState = True
td9.HorizontalAlign = WebControls.HorizontalAlign.Center
td9.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td9)
'td10.Text = dt.Rows(i)("[Field Header10]").ToString()
'td10.Font.Name = "Calibri"
td10.BackColor = ColorTranslator.FromHtml("#cccccc")
td10.ForeColor = Color.Black
'td10.Font.Size = 8
td10.BorderStyle = WebControls.BorderStyle.Inset
td10.BorderColor = Color.Black
td10.BorderWidth = 1.5
td10.EnableViewState = True
'/*** SHOULD DATA BE AVAILABLE CREATES ASP:BUTTON TO COPY TO CLIPBOARD LATER ***\'
If Len(dt.Rows(i)("[Field Header10]").ToString()) > 0 Then
Dim btn As New Button
td10.Controls.Add(btn)
btn.Text = dt.Rows(i)("[Field Header10]").ToString()
btn.Font.Name = "Calibri"
btn.Font.Size = 8
td10.HorizontalAlign = WebControls.HorizontalAlign.Center
td10.VerticalAlign = VerticalAlign.Middle
btn.EnableViewState = True
AddHandler btn.Click, AddressOf OnDbleClick
End If
tr.Controls.Add(td10)
td11.Text = dt.Rows(i)("[Field Header11]").ToString()
td11.Font.Name = "Calibri"
td11.BackColor = ColorTranslator.FromHtml("#cccccc")
td11.ForeColor = Color.Black
td11.Font.Size = 8
td11.BorderStyle = WebControls.BorderStyle.Inset
td11.BorderColor = Color.Black
td11.BorderWidth = 1.5
td11.EnableViewState = True
td11.HorizontalAlign = WebControls.HorizontalAlign.Center
td11.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td11)
td12.Text = dt.Rows(i)("[Field Header12]").ToString()
td12.Font.Name = "Calibri"
td12.BackColor = ColorTranslator.FromHtml("#cccccc")
td12.ForeColor = Color.Black
td12.Font.Size = 8
td12.BorderStyle = WebControls.BorderStyle.Inset
td12.BorderColor = Color.Black
td12.BorderWidth = 1.5
td12.EnableViewState = True
td12.HorizontalAlign = WebControls.HorizontalAlign.Center
td12.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td12)
td13.Text = dt.Rows(i)("[Field Header13]").ToString()
td13.Font.Name = "Calibri"
td13.BackColor = ColorTranslator.FromHtml("#cccccc")
td13.ForeColor = Color.Black
td13.Font.Size = 8
td13.BorderStyle = WebControls.BorderStyle.Inset
td13.BorderColor = Color.Black
td13.BorderWidth = 1.5
td13.EnableViewState = True
td13.HorizontalAlign = WebControls.HorizontalAlign.Center
td13.VerticalAlign = VerticalAlign.Middle
tr.Controls.Add(td13)
'/*** ADDS ROW ONCE CELLS ARE COMPLETE ***\'
itemstable.Controls.AddAt(rwcntr, tr)
rwcntr = rwcntr + 1
Next
end sub