I'm trying to do the following.
I want to use a gridview to load a set of associated
records dynamically based upon the input of the user.
I want the gridview to have a checkbox to the left of
the records and allow the user to use this to select
records to remove. The gridview will have pages and will
be sortable using the columns.
I had this working using a delete button, but when I went to using the checkbox it stopped sorting.
I'll try to make this a bit clearer.
1) A user enters in a bulk list of customer Ids
2) This add the customers to the grid, ID#, First Name, Last, etc.
3) After adding the customers, the user can then remove
selected customers. Originally this was done by the delete record link (which worked) but they want to be able to change their mind and use a checkbox to select and unselect which ones to delete.
4) Preferably they can page up and down the list, sort the list, etc while preserving the checkbox status, but they will live with a single page operation.
5) They want to be able to sort records based on columns.
I had this working before, but once I went to the checkbox version the sorting functioning broke!
So, what I'm seeking is an example of a page, using the gridview, with checkboxs and sortable columns that is not tied to a data source but is dynamically populated.
And if it makes a difference, I have the grid in a container of a website using a master page.
(Example of some of the code that I was using before to
create the original pages.)
I want to use a gridview to load a set of associated
records dynamically based upon the input of the user.
I want the gridview to have a checkbox to the left of
the records and allow the user to use this to select
records to remove. The gridview will have pages and will
be sortable using the columns.
I had this working using a delete button, but when I went to using the checkbox it stopped sorting.
I'll try to make this a bit clearer.
1) A user enters in a bulk list of customer Ids
2) This add the customers to the grid, ID#, First Name, Last, etc.
3) After adding the customers, the user can then remove
selected customers. Originally this was done by the delete record link (which worked) but they want to be able to change their mind and use a checkbox to select and unselect which ones to delete.
4) Preferably they can page up and down the list, sort the list, etc while preserving the checkbox status, but they will live with a single page operation.
5) They want to be able to sort records based on columns.
I had this working before, but once I went to the checkbox version the sorting functioning broke!
So, what I'm seeking is an example of a page, using the gridview, with checkboxs and sortable columns that is not tied to a data source but is dynamically populated.
And if it makes a difference, I have the grid in a container of a website using a master page.
(Example of some of the code that I was using before to
create the original pages.)
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
If Session("dtNewIntcodes") IsNot Nothing Then
Dim dt As DataTable = FormatProjectDataTable()
dt = Session("dtNewIntcodes")
gvCollectionList.DataSource = dt.DefaultView
gvCollectionList.DataBind()
End If
End If
End Sub
Protected Function FormatProjectDataTable() As DataTable
Dim dt As DataTable = New DataTable()
' Create Columns
dt.Columns.Add("Intcode", System.Type.GetType("System.String"))
dt.Columns.Add("First Name", System.Type.GetType("System.String"))
dt.Columns.Add("Last Name", System.Type.GetType("System.String"))
Dim PKColumn(0) As DataColumn
PKColumn(0) = dt.Columns("Intcode")
dt.PrimaryKey = PKColumn
Return dt
End Function
Private Sub AddInterview(ByVal Intcode As Integer)
Dim dt As DataTable = FormatProjectDataTable()
Dim dr As DataRow
Dim Conn As String
Conn = "..........." ' Removed for example
'Create a connection to the database
Dim objConn
objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(Conn)
If Session("dtNewIntcodes") IsNot Nothing Then dt = Session("dtNewIntcodes")
Dim strSQL As String
strSQL = "SELECT * FROM Custtable where intcode = " & Intcode.ToString
Dim objRS
objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open(strSQL, objConn)
'
Do While Not objRS.EOF
dr = dt.NewRow
dr("Intcode") = Right(" " + CStr(objRS("Intcode").value), 6)
dr("First Name") = objRS("FirstName").value
dr("Last Name") = objRS("LastName").value
dt.Rows.Add(dr)
objRS.MoveNext()
Loop
dt.AcceptChanges()
objConn.close()
Session("dvNewIntcodes") = dt.DefaultView
Session("dtNewIntcodes") = dt
gvCollectionList.DataSource = dt.DefaultView
gvCollectionList.DataBind()
End Sub
Comment