leachj
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
John,
I could give you an example, but you didn't talk about language.
Bob
I could give you an example, but you didn't talk about language.
Bob
ASKER
I am using VS2005 and Visual Basic.
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"></a sp:BoundFi eld>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
<!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-Size="Smaller" Width="100%" PageSize="20">
<HeaderStyle BackColor="SteelBlue" ForeColor="White" />
<Columns>
<asp:BoundField DataField="ZipCode" HeaderText="Zip" />
<asp:BoundField DataField="Attendees" HeaderText="Attendees"></a
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
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
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
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
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
ASKER
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?
Dim list As New List(Of Participants)
Type 'List' is not defined.
Do I need to add List property to the class?
ASKER
Never mind, I left out
Imports System.Collections.Generic
Imports System.Collections.Generic
ASKER
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
John
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
Bob
ASKER
Thanks