views:

62

answers:

2

I'm not sure how to go about this. Currently, in the first gridview, is a list of groups a member has access to. The second gridview is bound to a table that contains a list of every type of group and has an Add button which adds it to the first gridview and updates a table adding that group to a member.

This is what I am trying to do:

When the Add button (in the second gridview) for a row is clicked, it will be added to the first one (like it currently does), but I would also like it to disappear from the second gridview. So basically, a group should only be visible in either the first gridview or the second, not both. The problem I have is I don't want to modify the table because obviously the table contains all possible groups. Any suggestions?

A: 

I would do all the work on the database side. Data source for first one is:

Select g.*
From membership m
  inner join groups g on m.groupid=g.groupid
Where m.userid = @userid

Data source for the second one looks like

Select g.*
From groups g
Where not exists 
  (Select 1 from membership m 
  Where m.GroupID=g.GroupID and m.userid = @userid

Then your add button inserts the appropriate row in the table and requeries both grids.

Bill
A: 

You could simply make changes to the Dataset, then .AcceptChanges and re-bind. This would ensure the data would update on the screen without actually pushing it to the database.

Pseudo example:

Dim dt as Datatable = GetData1(strSQL.toString)
Dim dt2 as Datatable = GetData2(strSQL.toString)

Public Sub MoveRecord(ByVal dt1 as DataTable, ByVal dt2 as Datatable, ByVal index as Integer)

'Record being moved '
Dim dr as Datarow = dt.Rows(index)
dt2.Rows.Add(dr)
dt2.AcceptChanges
dt.Rows.RemoveAt(index)
dt.AcceptChanges

'Bind Gridview
 Perhaps store new changes in Viewstate,
 Cache, or Session for Paging, Sorting'
End Sub

Of course, this assumes the grids have the same fields. If they don't, you'd have to:

Dim drN as DataRow - dt2.Rows.NewRow
'Assign rows from moving datarow to new datarow'
dt2.Rows.Add(drN)
dt2.AcceptChanges
jlrolin