2 listboxes

collie

New member
2 listboxes

היי יש לי DATABASE עם 2 תבלות. יש לי LISTBOX שהוא צריך להיות populated ברגע שאני load את הדף. כאשר משתמש בוחר פריט מי הLISTBOX הראשון לדוגמה רכב הLISTBOX השני צריך לרשום את כל הרכבים שיש בתבלה השניה כמו BMW, FORD וכמו' איפה יש דוגמאות לזה בINTERNET? תודה
 

yuval k

New member
הממ...

זו לא בעיה מסובכת במיוחד, ואפשר לעשות את זה לא רע בצד-לקוח. בעיקרון, מה שקורה - אם עובדים בשיטה של WebForms - זה ככה: יש לך טבלא אחת, שמכילה את שמות ה"קטגוריות", וטבלא שניה, שמכילה את הערכים, כמו פה:
[categories] ID | Title 1 | Aeroplane Models 2 | Colours [items] ID | Category | ItemTitle 1 | 2 | Red 2 | 2 | Green 3 | 1 | Boeing 747​
את שולפת את רשימת הקטגוריות, עם השאילתה
select id, title from [categories];​
מגדירה DataSource וכו' (ה-value זה ה-id וה-text זה ה-title). באירוע של שינוי ה-index שמסומן, או בכל אירוע אחר שקורה אחרי שנבחרה קטגוריה (למשל, לחיצה על כפתור), את שולפת את רשימת הפריטים:
select id, itemTitle from [items] where category=...​
שוב, הגדרת DataSource וזהו
דוגמא לא מצאתי, וזה הכי קרוב לדוגמא
אגב, נא לא לבקש קודים מוכנים פה. מטרת הפורום שונה..
 

collie

New member
תודה ועוד שאלה

כמעט הצלחתי לעשות את זה. זה עדיין לא עובד לי כמו שאני צריכה אבל אני יעבוד על זה עוד קצת לפני שהבקש עזרה. הDB שלי זה SQL SERVER אבל אני צריכה את זה ב ACCESS. אני לא יודעת איך לעשות את הconnectionstring בSQL זה כך: Dim strConn as string = "server=(local);uid=sa;pwd=;database=listbox_practice"
 

collie

New member
עזרה בבקשה

היי כתבתי את הcode ואני חושבת שה connection שלי לACCESS זה נכון אבל יש לי error בcode . הקוד מצורף
 

collie

New member
i solved my little problem

the Model mentioned came from datatextfield=model for listbox 1 i changed the property to the relevant name and it fixed it. however now i'm having other problems.
so you will hear from me soon
 

collie

New member
now i really need help

the code for my application is included in my previous mail. the 2 tables that i have in the db are as follows Models Table modelID modelName makeID 1 Escort 1 2 Mustang 1 3 Windstar 1 4 Sunfire 2 5 Firebird 3 6 Montana 4 MAKES TABLE makeID makeName 1 Ford 2 Pontiac 3 Chevrolet 4 Hyundai The first listbox gets populated from the makes table however when i clikc the button to get the 2nd list populated according to what was chosen in the first listbox i get an error page (attached)
 

collie

New member
ADODB

עכשיו בעבודה ביקשו שאני יעבוד עם ADODB. אבל אני לא מוצאת בINTERNET מאמר בנושא ואני לא יודעת איך transfer את מה שכתבתי ל ADODB. אני רק יודעת שאני צריכה את הREFERENCE . מה לעשות?
 

gilad g

New member
לא הבנתי

את צריכה לתרגם את זה חזרה ל-ADO קלאסי? ....Might as well rewrite the whole thing all over again
 

collie

New member
זה מה שהם רוצים

אני צריכה בREFERENCE לבחור ADODB ולהשתמש ב RECORDSETS וב ADODB.Connection() נראה לי משהו כמו בASP רגיל. אני לא מוצאת שום דבר בספרים שמסביר איך לעשות את זה ב .NET כי רוב הדוגמאות זה ב ADO.NET אני לא יודעת מה לעשות. ראיונות??
 

collie

New member
another question

אני ממש מצטערת עם כל השאלות שלי אבל אני ממש זקוקה לעזרה. אני מקווה שבהמשך אני יוכל לעזור לכם במקום שאתם תעזרו לי . בדוגמא שנתנה לי לא מופיע Imports System.Data Imports ADODB Imports System.Data.OleDb יש reason לזה? אם אני רוצה bind data from a table to a listbox אני צריכה להשתמש בDATABIND ו ב RS.FILL ? (דרך אגב-אפשר לכתוב את ההודעות באנגלית?) זה הקוד שיש לי עד עכשיו אבל זה מחזיר רק את הרשומה האחרונה בטבלה במקום את הכל והוא כותב את זה מוזר (מצורף) הקוד Imports System.Data Imports ADODB Imports System.Data.OleDb Public Class listboxADO Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Page.IsPostBack Then Dim cn As New ADODB.Connection cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/database/duclassified.mdb")) Dim rs As New ADODB.Recordset rs.Open("Select * from cats", cn) Dim strCat As String If rs.BOF And rs.EOF Then Response.Write("no records found") Else rs.MoveNext() Do While Not rs.EOF strCat = (rs("cat_name").Value & "<br>") Response.Write(strCat) rs.MoveNext() Loop Response.Write("end of data") End If List1.DataSource = strCat List1.DataBind() List1.SelectedIndex = 0 rs.Close() rs = Nothing
 

collie

New member
יישרתי לשמאל את הקוד החדש

אני כותבת באנגלית כי הרבה יותר קל לי ויותר מהר. אם זה לא מקובל אז נא לומר לי ואני יכתוב בעברית but now the real problem will start. When the user selects an item from the list another listbox needs to open with the corresponding values. eg. if user selects in the first listbox cars then second listbox must be populated with bmw, honda, porsche etc. I have 2 separate tables in Access. זה הקוד שעובד למי שצריך- Imports System.Data Imports ADODB Imports System.Data.OleDb Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Page.IsPostBack Then Dim cn As New ADODB.Connection cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/database/duclassified.mdb")) Dim rs As New ADODB.Recordset rs.Open("Select * from cats", cn) Dim strCat As String If rs.BOF And rs.EOF Then Response.Write("no records found") Else Do While Not rs.EOF strCat = (rs("cat_name").Value) List1.Items.Add(strCat) rs.MoveNext() Loop Response.Write("end of data") End If List1.SelectedIndex = 0 rs.Close() rs = Nothing End If End Sub​
 

collie

New member
../images/Emo24.gifהצלחתי. הדוגמא שנתתה לי עזרה

אני כותבת באנגלית כי הרבה יותר קל לי ויותר מהר. אם זה לא מקובל אז נא לומר לי ואני יכתוב בעברית but now the real problem will start. When the user selects an item from the list another listbox needs to open with the corresponding values. eg. if user selects in the first listbox cars then second listbox must be populated with bmw, honda, porsche etc. I have 2 separate tables in Access. זה הקוד שעובד למי שצריך- Imports System.Data Imports ADODB Imports System.Data.OleDb Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not Page.IsPostBack Then Dim cn As New ADODB.Connection cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/database/duclassified.mdb")) Dim rs As New ADODB.Recordset rs.Open("Select * from cats", cn) Dim strCat As String If rs.BOF And rs.EOF Then Response.Write("no records found") Else Do While Not rs.EOF strCat = (rs("cat_name").Value) List1.Items.Add(strCat) rs.MoveNext() Loop Response.Write("end of data") End If List1.SelectedIndex = 0 rs.Close() rs = Nothing End If End Sub
 
למעלה