Good Evening 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()
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")
'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)
lbItems.DataValueField = "PartNumber"
lbItems.DataValueField = "NSN"
lbItems.DataValueField = "PartName"
lbItems.DataBind()
End Sub
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 the Listbox receives focus, but no list items are visible. I've created several list items in the aspx page, however I don't know how to populate the contents of my datatable in the listbox. Can someone help a newbie with this, seemingly, easy issue?
Thanks,
Sid