Data Grid will not display

G

Guest

Thanks for the Help in Advance!!

I am a beginner in VB.Net. I am trying to create a form which is displayed in a email for our customers to fill in a Request for quote. I would like them to type data into fields and have it added to the Datagrid.

I am constantly getting the error Column 'OALen' does not belong to table .

Any Ideas?


Public tblJobItems As New DataTable

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not (Page.IsPostBack) Then

'Sequence
Dim Sequence As DataColumn = New DataColumn
With Sequence
.DataType = System.Type.GetType("System.Int32")
.ColumnName = "Sequence"
.AllowDBNull = False
.ReadOnly = True
.AutoIncrement = True
End With
tblJobItems.Columns.Add(Sequence)

'Quantity
Dim Quantity As DataColumn = New DataColumn
With Quantity
.DataType = System.Type.GetType("System.Int32")
.ColumnName = "Quantity"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(Quantity)

'FamilyType
Dim FamilyType As DataColumn = New DataColumn
With FamilyType
.DataType = System.Type.GetType("System.String")
.ColumnName = "FamilyType"
.ReadOnly = False
.AutoIncrement = False
.Caption = "Truss Type"
End With
tblJobItems.Columns.Add(FamilyType)

' Over All Length
Dim OAL As DataColumn = New DataColumn
With OAL
.DataType = System.Type.GetType("System.String")
.ColumnName = "OALen"
.ReadOnly = False
.AutoIncrement = False
.Caption = "Over all Length"
End With
tblJobItems.Columns.Add(OAL)

'Heel
Dim Heel As DataColumn = New DataColumn
With Heel
.DataType = System.Type.GetType("System.String")
.ColumnName = "Heel"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(Heel)

'Item Description
Dim Description As DataColumn = New DataColumn
With Description
.DataType = System.Type.GetType("System.String")
.ColumnName = "Description"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(Description)

'Pitch
Dim Pitch As DataColumn = New DataColumn
With Pitch
.DataType = System.Type.GetType("System.String")
.ColumnName = "Pitch"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(Pitch)

'LOverHange
Dim LOverHang As DataColumn = New DataColumn
With LOverHang
.DataType = System.Type.GetType("System.String")
.ColumnName = "LOH"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(LOverHang)

'ROverHang
Dim ROverHang As DataColumn = New DataColumn
With ROverHang
.DataType = System.Type.GetType("System.String")
.ColumnName = "ROH"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(ROverHang)

'LCant
Dim LCant As DataColumn = New DataColumn
With LCant
.DataType = System.Type.GetType("System.String")
.ColumnName = "LCant"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(LCant)

'RCant
Dim RCant As DataColumn = New DataColumn
With RCant
.DataType = System.Type.GetType("System.String")
.ColumnName = "RCant"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(RCant)

'BearingSize
Dim BearingSize As DataColumn = New DataColumn
With BearingSize
.DataType = System.Type.GetType("System.String")
.ColumnName = "BearingSize"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(BearingSize)

'SpecialNotes
Dim SpecialNotes As DataColumn = New DataColumn
With SpecialNotes
.DataType = System.Type.GetType("System.String")
.ColumnName = "SpecialNotes"
.ReadOnly = False
.AutoIncrement = False
End With
tblJobItems.Columns.Add(SpecialNotes)
' Create an array for DataColumn objects.
Dim keys(0) As DataColumn
keys(0) = Sequence

Dim PrimaryKeyColumns(0) As DataColumn
PrimaryKeyColumns(0) = tblJobItems.Columns("Sequence")
tblJobItems.PrimaryKey = PrimaryKeyColumns
End If
DataGrid1.DataSource = tblJobItems
DataGrid1.DataBind()

End Sub

Private Sub btnADDTrussItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADDTrussItem.Click

'Insert new row into the dataset table
Dim dr As DataRow = tblJobItems.NewRow()
dr("OALen") = tbOAL.Text
dr("Heel") = ddlHeel.SelectedValue
tblJobItems.Rows.Add(dr)
'Refresh the grid
DataGrid1.EditItemIndex = -1
End Sub
 
G

Guest

Hi Leo

The reason might be the variable tblJobItems. Though you define as public, it will not persist through posting back. You might consider using ViewState to store it, like
Private tblJobItems As DataTabl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
If Not (Page.IsPostBack) The
'Build datatabl
Els
'Get table from ViewStat
tblJobItems = CType(ViewState("tblJobItems"), DataTable
End I
DataGrid1.DataSource = tblJobItem
DataGrid1.DataBind(
End Su

Private Sub Page_Prerender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRende
'Save table back to ViewStat
ViewState("tblJobItems") = tblJobItem
End Su
Hope this will help

Bin Song, MC
 
S

Steven Cheng[MSFT]

Thanks for Bin's good suggestions.

Hi Leo,

I agree with Bin's solution. In addition to the "ViewState", you can also
use SessionState to maintain DataSource between the page's post back. There
is a example on this in the following link:

#DataGrid.SortCommand Event
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontro
lsdatagridclasssortcommandtopic.asp?frame=true

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Leo,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DataGrid using a table not a DataSet 0
Solution Required 2
Master/Detail 0
Master/Detail 0
Add DataColumn to DataSet 1
Data Binding Issue 0
Proper use of Interfaces? 2
Filter Data 8

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top