473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need some help with Grid view

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.)

Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.         If Me.IsPostBack = False Then
  3.             If Session("dtNewIntcodes") IsNot Nothing Then
  4.                 Dim dt As DataTable = FormatProjectDataTable()
  5.                 dt = Session("dtNewIntcodes")
  6.                 gvCollectionList.DataSource = dt.DefaultView
  7.                 gvCollectionList.DataBind()
  8.             End If
  9.         End If
  10.  
  11.     End Sub
  12.  
  13.   Protected Function FormatProjectDataTable() As DataTable
  14.         Dim dt As DataTable = New DataTable()
  15.         ' Create Columns
  16.         dt.Columns.Add("Intcode", System.Type.GetType("System.String"))
  17.         dt.Columns.Add("First Name", System.Type.GetType("System.String"))
  18.         dt.Columns.Add("Last Name", System.Type.GetType("System.String"))
  19.  
  20.         Dim PKColumn(0) As DataColumn
  21.  
  22.         PKColumn(0) = dt.Columns("Intcode")
  23.         dt.PrimaryKey = PKColumn
  24.  
  25.  
  26.         Return dt
  27.     End Function
  28.  
  29.     Private Sub AddInterview(ByVal Intcode As Integer)
  30.  
  31.         Dim dt As DataTable = FormatProjectDataTable()
  32.         Dim dr As DataRow
  33.  
  34.         Dim Conn As String
  35.         Conn = "..........." ' Removed for example
  36.  
  37.         'Create a connection to the database
  38.         Dim objConn
  39.         objConn = Server.CreateObject("ADODB.Connection")
  40.         objConn.Open(Conn)
  41.  
  42.  
  43.         If Session("dtNewIntcodes") IsNot Nothing Then dt = Session("dtNewIntcodes")
  44.  
  45.         Dim strSQL As String
  46.         strSQL = "SELECT * FROM Custtable where intcode = " & Intcode.ToString 
  47.  
  48.         Dim objRS
  49.         objRS = Server.CreateObject("ADODB.Recordset")
  50.         objRS.Open(strSQL, objConn)
  51.         '
  52.  
  53.         Do While Not objRS.EOF
  54.             dr = dt.NewRow
  55.             dr("Intcode") = Right("     " + CStr(objRS("Intcode").value), 6)
  56.             dr("First Name") = objRS("FirstName").value
  57.             dr("Last Name") = objRS("LastName").value
  58.             dt.Rows.Add(dr)
  59.             objRS.MoveNext()
  60.         Loop
  61.         dt.AcceptChanges()
  62.  
  63.         objConn.close()
  64.  
  65.         Session("dvNewIntcodes") = dt.DefaultView
  66.         Session("dtNewIntcodes") = dt
  67.         gvCollectionList.DataSource = dt.DefaultView
  68.         gvCollectionList.DataBind()
  69.  
  70.     End Sub
  71.  
Mar 25 '11 #1
3 1604
kadghar
1,295 Expert 1GB
What you need is to put some code in each event. e.g. keep a record of the selected rows in the 'select row' event of the grid, make a sorted query in the sort event of the grid, change the grid page in the 'page change' event... and so on.

It's kinda boring, but it isn't that hard to do.
Mar 27 '11 #2
Thanks, but I do have the events, though perhaps they are
now malformed. Like I noted, it was working UNTIL I added
the checkbox using the asp template method. After that,
the hyperlinks that trigger the sorting disappeared.
Mar 27 '11 #3
kadghar
1,295 Expert 1GB
Thats weird...

Check you're allowing sorting and validation. Also check the columns you can sort have a sorting expresion you'll later retrieve in you code.

Here's an excercise I made with some columns that can be sorted and some that can't, a couple of buttons and a template:

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" style="margin-left: 0px; font-size: small; text-align: center;" Width="1025px" Height="16px" AllowPaging="True" AllowSorting="True" EnableModelValidation="True">
  2.     <RowStyle Font-Bold="False" />
  3.     <Columns>
  4.         <asp:BoundField DataField="id_inc" HeaderText="id" SortExpression="id_inc" />
  5.         <asp:BoundField DataField="descrip" HeaderText="descripción" SortExpression="descrip" />
  6.         <asp:BoundField DataField="producto" HeaderText="producto" SortExpression="producto" />
  7.         <asp:BoundField DataField="fecha_alta" HeaderText="agregado"  SortExpression="fecha_alta" dataformatstring="{0:dd-MMM-yyyy}"/>
  8.         <asp:BoundField DataField="fecha_comp" HeaderText="compromiso" SortExpression="fecha_comp" dataformatstring="{0:dd-MMM-yyyy}"/>
  9.         <asp:BoundField DataField="estado" HeaderText="estado" SortExpression="estado" />
  10.         <asp:BoundField DataField="responsable" HeaderText="responsable" SortExpression="responsable"/>
  11.         <asp:CommandField ButtonType="Image" EditImageUrl="~/edit.png" ShowEditButton="True" />
  12.         <asp:CommandField ButtonType="Image" SelectImageUrl="~/info.png" ShowSelectButton="True" />
  13.         <asp:TemplateField>
  14.             <ItemTemplate><asp:CheckBox ID="CheckBox1" runat="server" /></ItemTemplate>
  15.         </asp:TemplateField>
  16.     </Columns>
  17.     <PagerStyle Font-Bold="True" Font-Italic="False" ForeColor="#666666" />
  18.     <HeaderStyle Font-Bold="True" ForeColor="#666666" />
  19. </asp:GridView>
Sorry about the spanish. It works perfectly, perhaps you can use it to compare what elements you're missing.
Mar 28 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: puja | last post by:
hi all, am using grid view in asp.net 2.0 . My problem is easy but can't get it to work. My grid view id = grdContract and am binding grid view using dataset My dataset returns 5 columns from...
3
by: CK | last post by:
How can I get this value at runtime? I want the value of the row as it's created. Any ideas?
2
by: Umeshnath | last post by:
Hi, I have placed a grid view inside Atlas panel. On click of a button event, data is populated in the grid view, I want to add scroll bar instead of increasing the size of grid view. I have...
0
by: nanaalwi | last post by:
hi there, im doing a project right now to download a data from EEPROM of a camcorder. i used a 'data grid view' to display all the data downloaded from the camcorder. however, i have to save the...
1
by: =?Utf-8?B?TG95b2xhIHN0YWxpbg==?= | last post by:
Hi, I am using ASP.Net 2.0 version and Windows'XP OS. I am useing the Grid view control to display the user details along with the paging concept provided by the grid view control. When i...
2
by: rameshgohil | last post by:
I am using grid view and a button column in it using <itemTemplate> but I am not able to rerive cell value of a selected row from grid view. I have tried the following to methods in Row_command...
2
by: poornimanithya76 | last post by:
Hi, i am tried to convert below piece of code from data grid to grid view. since grid view is not having item created event so i try to implement with row Created. i am unable to perform whole...
4
by: pradeep c | last post by:
I am new vb.net im am developing a stand alone application, can some one help me how to get and display datas which are in grid view to craystal report?
1
by: 111111222222 | last post by:
Hi All, As of now I am populating grid view using code behind. I want to place a textbox and a button to search the grid view using TIN which is one column in my grid view. I placed the textbox...
1
by: rajsrmc | last post by:
Hello Guys! I have a mysql table which is connected with aspx page in grid view, in the connected table i have assigned Serial number column as Primary key and as well in auto increment, by using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.