Hello All,
I am writing a page that allows users to search a parts table, select quantities and a listbox is to be populated with gridview values. Here's a snippet of my aspx page:
<asp:ListBox runat="server" ID="lbItems" Width="155px">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:ListBox>
Here's the relevant contents of codebehind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Define DataTable Columns as incoming gridview fields
Dim dtSelParts As DataTable = New DataTable
Dim dr As DataRow = dtSelParts.NewRow()
Dim PartName, NSN, PartNumber, Qty, NewPart As String
dtSelParts.Columns.Add("PartNumber")
dtSelParts.Columns.Add("NSN")
dtSelParts.Columns.Add("PartName")
dtSelParts.Columns.Add("Qty")
'Select those gridview rows that have txtQty <> 0
For Each row As GridViewRow In MySearch.Rows
Dim textboxText As String = _
CType(row.FindControl("txtQty"), TextBox).Text
If textboxText <> "0" Then
'Create the row
dr = dtSelParts.NewRow()
'Fill the row with data
dr("PartNumber") = MySearch.DataKeys(row.RowIndex)("PartNumber")
dr("NSN") = MySearch.DataKeys(row.RowIndex)("NSN")
dr("PartName") = MySearch.DataKeys(row.RowIndex)("PartName")
dr("Qty") = MySearch.DataKeys(row.RowIndex)("Qty")
'Add the row to the table
dtSelParts.Rows.Add(dr)
End If
Next
'Need to send items to Listbox control lbItems
lbItems.DataSource = New DataView(dtSelParts)
If dtSelParts.Rows.Count > 0 Then
For i As Integer = 0 To dtSelParts.Rows.Count - 1
PartNumber = dtSelParts.Rows(i)("PartNumber").ToString()
NSN = dtSelParts.Rows(i)("NSN").ToString()
PartName = dtSelParts.Rows(i)("PartName").ToString()
Qty = dtSelParts.Rows(i)("Qty").ToString()
NewPart = (PartNumber & " - ") + NSN + (PartName & " - ") + Qty
lbItems.Items.Add(New ListItem(NewPart))
lbItems.DataTextField = NewPart
Next
End If
lbItems.DataBind()
End If
The page runs fine in that my search functiobnality is intact, and I can input quantity values into my gridview's textbox. When I click Add to Quote, no list items are visible. I don't have any ListItems within my Listbox control in my ASPX page. Can someone help a newbie with this, seemingly, easy issue?
Thanks, Sid