Hi counterkin,
You will need to add Rows and bind DataTable to GridView inside the IsPostBack condition.
As you add Serial No column name as parameter to ToTable method you will also need to add the ID column name into it.
Me.GridView.DataSource = DirectCast(ViewState("Inventory"), DataTable).DefaultView.ToTable(True, "ID", "SerialNo")
You can Refer the Code below.
If Not IsPostBack Then
ViewState("Inventory") = Nothing
Dim DT_serialno As New DataTable
DT_serialno.Columns.AddRange(New DataColumn(1) {New DataColumn("ID"), New DataColumn("SerialNo")})
'Add Row
DT_serialno.Rows.Add("10123", "ABC101")
DT_serialno.Rows.Add("10124", "ABC124")
DT_serialno.Rows.Add("10123", "ABC101")
DT_serialno.Rows.Add("10126", "ABC126")
ViewState("Inventory") = DT_serialno
'Remove duplicated rows
Me.GridView.DataSource = DirectCast(ViewState("Inventory"), DataTable).DefaultView.ToTable(True, "ID", "SerialNo")
Me.GridView.DataBind()
End If
Screenshots