I have the following code
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim counter As Integer = 0
Dim t As DataTable = DirectCast(Session("MyDataTable"), DataTable)
Dim row1 As DataRow = t.NewRow()
If (isUnique(t) And counter < 30) Then
row1("ID") = counter + 1
row1("univirsityID") = ddlUnivs.SelectedValue
row1("majorID") = ddlMajors.SelectedValue
row1("UniName") = ddlUnivs.SelectedItem.Text
row1("MajorName") = ddlMajors.SelectedItem.Text
t.Rows.Add(row1)
Session("MyDataTable") = t
GridView1.DataSource = t
GridView1.DataBind()
lblMsg.Text = "تم اضافة الرغبة"
counter = counter + 1
Else
lblMsg.Text = "سبق لك ادخال الرغبة"
End If
End Sub
The problem is the row1(“ID”) dose not change it keeps getting the value of 1 for all rows added to datatable
any help is appreciated
thanks in advance.
Remove your current counter declaration (for the reasons everyone has been posting) and put this on top of your class:
This way you are saving your
countervariable in the statefull ViewState of your page, and it won’t get lost after a page-cycle.