• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Is it possible to use an unbound gridview to collect data entry?

I have a form that will require the entry of about 20 zipcodes with a number total for participants within those zipcodes.  

Zip        Attendees
65212        2
65284        5
65202        10
etc.

I'm thinking an unbound gridview or maybe a table.  I have not been able to figure out how to use the gridview unbound for data entry.  Also not sure if growing a table dynamicly  is the right solution.  I would like the control to scroll so it does not take up page space.  I would like to enter all the zips and numbers before making a trip to the server.  The number of entries will vary widely from as few as 3 zip codes to as many as 30.  I am unsure as to how I can approach this.  Could someone point me in the right direction?

Thanks,
John
0
leachj
Asked:
leachj
  • 6
  • 5
1 Solution
 
Bob LearnedCommented:
You could define a class with properties, and then create a list of instances of that class, and then bind the GridView to the list.

Bob
0
 
leachjAuthor Commented:
I reviewed classes over the weekend, but I am still not clear on your suggestion.  Could you elaborate some?
Thanks
0
 
Bob LearnedCommented:
John,

I could give you an example, but you didn't talk about language.

Bob
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leachjAuthor Commented:
I am using VS2005 and Visual Basic.
0
 
Bob LearnedCommented:
Default page:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridView Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div style="overflow: auto; width: 600px; height: 400px;">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Font-Names="Tahoma"
                Font-Size="Smaller" Width="100%" PageSize="20">
                <HeaderStyle BackColor="SteelBlue" ForeColor="White" />
                <Columns>
                    <asp:BoundField DataField="ZipCode" HeaderText="Zip" />
                    <asp:BoundField DataField="Attendees" HeaderText="Attendees"></asp:BoundField>
                </Columns>
            </asp:GridView>
        </div>
    </form>
</body>
</html>
0
 
Bob LearnedCommented:
Default code-behind:

Imports System.Collections.Generic

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            Me.LoadGridData()
        End If
    End Sub

    Private Sub LoadGridData()

        Dim list As New List(Of Participants)
        list.Add(New Participants(65212, 2))
        list.Add(New Participants(65284, 5))
        list.Add(New Participants(65202, 10))

        Me.GridView1.DataSource = list
        Me.GridView1.DataBind()

    End Sub
End Class
0
 
Bob LearnedCommented:
Class:

Public Class Participants

    Public Sub New(ByVal zipCode As Integer, ByVal attendees As Integer)
        m_zipCode = zipCode
        m_attendees = attendees
    End Sub

    Private m_zipCode As Integer
    Public Property ZipCode() As Integer
        Get
            Return m_zipCode
        End Get
        Set(ByVal value As Integer)
            m_zipCode = value
        End Set
    End Property

    Private m_attendees As Integer
    Public Property Attendees() As Integer
        Get
            Return m_attendees
        End Get
        Set(ByVal value As Integer)
            m_attendees = value
        End Set
    End Property

End Class

Bob
0
 
leachjAuthor Commented:
I get an error here...

Dim list As New List(Of Participants)

Type 'List' is not defined.

Do I need to add List property to the class?
0
 
leachjAuthor Commented:
Never mind, I left out
Imports System.Collections.Generic
0
 
leachjAuthor Commented:
I have gotten this to work, thanks.  I will award points.  I have a question though regarding the sort property of the gridview.  It does not seem to be available to me.  I have set the allowsorting property of the gridview but it is not enabled.  Is it related to the way in which the control was created?

John
0
 
Bob LearnedCommented:
The AllowSorting only works if you are bound to an SqlDataSource.  If you aren't then you need to handle the sorting event yourself.

Bob
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now