Listboxes w/o postback

collie

New member
Listboxes w/o postback

Hi, I desperately need help. i have no idea how to do what my boss asked for
OK. Currently i have 2 listboxes with postback that get populated from an ACCESS db. When a user selects an item from the first listbox the 2nd gets populated accordingly. All this is done with classic ADO and no datasets etc. Everything works great. However, now my boss despite my protests decided to use all the above but w/o a postback to the server everytime a new item is selected from list1. He wants to use jscript in vb.net. However, i have looked everywhere for help on how to start and nobody can help me. All the examples use ado.net and datasets. Can someone please please help? Thanks
 

yuval k

New member
Hmm...

First of all, can you please align your messages left, like code? Thank you
Well... you can populate the 2nd listbox from a JavaScript bidimensional array, or you can use XML (which you can get dynamically using XMLHTTP) and the DOM functions.​
 

yuval k

New member
nope...

She has an array of options for each value selected in the first listbox... not one item.​
 

collie

New member
can you please point me to a

tutorial on how to do multidimensional arrays with a db or to examples or whatever so that i can get started as i have no idea how to proceed. Thanks​
 

collie

New member
listbox

Below is what i tried to do based on an example that i found. however, this code creates the listboxes at runtime and i don't want that. i want to add the listboxes in design and just add the items to it such as listbox1.add.item Also, with this code when i click a different category the subcategory doesn't change for some reason. I have also include the source that i get when i do view source. Why is tractor always repeated? If Not Page.IsPostBack Then Dim objconn As New ADODB.Connection objconn.Open(YBayTools.Constants.ConnectionString) Dim rsCAT As New ADODB.Recordset Dim sCategory Dim liCategory As New ListBox Dim liSubsCategory As New ListBox Dim AD_ID = "3059" Dim rsSubs As New ADODB.Recordset ' rsSubs.Open("SELECT * from SUBS where cat_ID = " & category.SelectedItem.Value.ToString, objconn) rsSubs.Open("select * from subs", objconn) rsCAT.Open("SELECT * FROM CATS ORDER BY cat_name ASC", objconn) If rsCAT.EOF Then Response.Write("No category.<BR>") Else ' write the CATEGORY listbox... Response.Write("<select id=""licategory"" SIZE=15" & _ " OnSelectedIndexChanged=""manuselected(this);"" >") ' write the entry code for the javascript... Dim sJavaScript = "function manuselected(elem){" & Environment.NewLine & _ "for (var i = liSubsCategory." & _ "options.length; i >= 0; i--){" & Environment.NewLine & _ "liSubsCategory.options = null;" & _ Environment.NewLine ' loop through the recordset... Do Until rsCAT.EOF ' is this a new category? Dim catname = rsCAT("cat_name").Value If (sCategory) <> "CATName" Then ' if so, add an entry to the first listbox sCategory = rsCAT("CAT_Name").Value Dim sCatId = rsCAT("CAT_ID").Value Response.Write("<OPTION VALUE=" & sCatId & ">" & sCategory & "</OPTION>") ' and add a new section to the javascript... sJavaScript = sJavaScript & "}" & Environment.NewLine & "if (elem.options[elem.selectedIndex].value==" & rsCAT("CAT_ID").Value & "){" & Environment.NewLine & "" End If ' and add a new SubsCategory line to the javascript... sJavaScript = sJavaScript & _ "liSubsCategory.options[" & _ "liSubsCategory.options.length] = new Option('" & _ rsSubs("sub_NAME").Value & "','" & rsSubs("sub_ID").Value & "');" & _ Environment.NewLine rsCAT.MoveNext() Loop ' finish the category listbox... Response.Write("</select>") liCategory.SelectedValue = 8 &nbs
 

collie

New member
Object lost with postback

I have a page that on page load the fields have to be loaded with details from the db. I have a save button that is clicked afterwards. However, the object gets lost (object=nothing) and it doesn't update the fields. Why? it returns order=nothing after the save My code is included.​
 

gilad g

New member
That's because

You have to make the object persistant in the ViewState. change Order's declaration to be like so: Public Property Order() As YBayTools.PayOrder Get Return CType(ViewState.Item("myOrder"), YBayTools.PayOrder) End Get Set(Value AsY BayTools.PayOrder) ViewState.Item("myOrder") = Value End Set End Property Yuck.. i hate VB.NET
Ever thought of moving to C#?​
 

collie

New member
must i write that

in the same place as where i originally declared Orders (before the page_load event)? Why am i using vb.net: coz i learnt vb6 and i think vb.net is closer to vb6 than c# and as u have noticed i am having a hard time with vb.net so before i move to c# i want to get vb.net right
 

collie

New member
I get an error

I put it where i orginially declared the order and i get the following error: -------------------------------------------------------------------------------- The type 'YBayTools.PayOrder' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.​
 

gilad g

New member
Hmmm

you need to make your PayOrder class serializable if you want to save it in the ViewState... sorry i forgot to mention that
In C#, you would add a Serializable Attribute, I think in VB.NET it's done like so: <Serializable> _ Public Class PayOrder...​
 

collie

New member
enum class

Hi, I have a class that I need to read from another project. I need to add the items (creditcard, check etc.) in the class to a listbox. I wrote a code that works but I prefer writting a code that uses MinPayOrderTypeEnum and MaxPayOrderTypeEnum. not sure how to do that. Here is the class: Public Class PayOrder Public Enum PayOrderTypeEnum ' ??? ????? Unknown = 0 Cash = 1 Check = 2 CreditCard = 3 End Enum Public Const MinPayOrderTypeEnum As Int32 = 0 Public Const MaxPayOrderTypeEnum As Int32 = 3 This is the code with the listbox that i wrote: Dim payOrder As Type = GetType(PayOrder.PayOrderTypeEnum) For Each str In [Enum].GetNames(payOrder) pli = New ListItem(str) LiPayType.Items.Add(pli) Next str​
 

collie

New member
i have more questions..like duh../images/Emo13.gif

First thanks for the quick response from both the forum managers. I thought that automatically aligns left as i wrote it in the jafi forum. Sorry about that. Ok now for my problem: Gr8 u guys mention arrays but how on earth do i use it w/o datasets and from a db???
In my exisiting code the first listbox gets populate with the code below. Must i keep it like that or change it? Thanks CODE for 1st listbox Dim rs As New ADODB.Recordset rs.Open("SELECT * FROM cats ORDER BY cat_name ASC", cn) Dim strCat As String Dim strCatid As String Dim li As ListItem If rs.BOF And rs.EOF Then Response.Write("no records found") Else Do While Not rs.EOF li = New ListItem(rs("cat_name").Value, rs("cat_id").Value) List1.Items.Add(li) rs.MoveNext() Loop End If rs.Close() rs = Nothing SECOND LISTBOX Dim rsSub As New ADODB.Recordset rsSub.Open("SELECT sub_name, sub_id FROM subs WHERE cat_id=" & cat_id.ToString & " ORDER BY sub_name ASC", cn) Dim l_item As ListItem Do While Not rsSub.EOF l_item = New ListItem(rsSub("sub_name").Value, rsSub("sub_id").Value) List2.Items.Add(l_item) rsSub.MoveNext() Loop List2.SelectedValue = sub_id rsSub.Close() rsSub = Nothing cn.Close() End If End If End Sub Protected Sub Select1Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim cn As New ADODB.Connection cn.Open(YBayTools.Constants.ConnectionString) Dim rs As New ADODB.Recordset Dim li As ListItem rs.Open("Select * from subs where cat_ID =" & List1.SelectedItem.Value.ToString, cn) 'rs.Open("Select * from subs where cat_ID ='" & List1.SelectedItem.Text.ToString & "' & List1.SelectedItem.value.ToString", cn) Dim strCat As String If List2.Items.Count > 0 Then List2.Items.Clear() End If If rs.BOF And rs.EOF Then Response.Write("no records found") Else Do While Not rs.EOF li = New ListItem(rs("sub_name").Value, rs("sub_id").Value) List2.Items.Add(li) rs.MoveNext() Loop End If rs.Close() rs = Nothing cn.Close()​
 

collie

New member
Hebrew and alignment

Hi, In .net I have a table with labels and textboxes. I need to align everything right and where the user has to enter numbers then dir=left and where user enters letters such as name then dir=right. I tried doing it but it doesn't work. An example of what happens is attached.​
 
למעלה