G
Guest
Hi, I wonder if anyone can help?
I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:
Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow
Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub
Thanks in advance
Julia
I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:
Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow
Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub
Thanks in advance
Julia