Hi, after several failed attempts to retrieve and display datafrom the database, I've decided to go back to the basic and try something simpler.
I've established connection to the database, retrieved data from the ResumeID and the Resumes fields of my ResumesDB database.
Then they are bound to my list box in Page_Load like the following:
Me.ListBox1.items.Clear()
Dim myConnectionAs OdbcConnection
my Connection =New OdbcCOnnection (DBConn =New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myServer;Database=ResumesDB;User=myUserassword=myPass;Option=3;")
Dim AD asNew OdbcDAtaAdapter("SELECT ResumeID, Resumes From Professions", myConnection)Dim DS asNew Dataset
AD.Fill(DS)
AD.Dispose()
Me.ListBox1.DataSource=DS
Me.ListBox1.DataTextField="Resumes"
Me.ListBox1.DataSource=DS="ResumesID"
Me.ListBox1.Databind()
Then in the Button1_Click section of my codebehind, I used a label to display the data like the following.Theresults when I click Button1 are that my list items are replaced by thedata from the database, and Label1 actually displays the data.Label1.Text=Listbox.SelectedItem.Text().
However, that is not what I had in mind. My list box contains names ofdifferent professions, when one of them is selected and Button1 is
clicked, the resume that corresponds to the profession in theProfessions field will be retrieved and displayed. The mostdifficult thing
for me right now is displaying large data like a resume or a textartcle. The other problem is displaying more than one resume on the same
page if more than one should be retrieved. Please help me resolve thisproblem, I've had many failed attempts and its quite frustrating.
Thank you in advance for your help.
Maybe you should consider using a GridView combined with a DetailsView. The gridview would take the place of your listbox. The DetailsView only shows details for a single record, but using these controls could make your life a lot easier. Here is a quick tutorial with working examples:
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/detailsview.aspx
Thanks for your response but unfortunately I am not using asp.net 2.0. Is there something similar in asp.net 1.x that I can use?
The DataGrid is a precursor to the GridView control that is available in .NET 1.x. Here is a brief tutorial: http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/doc_datagrid.aspx
The Repeater is another one that you could use. Here is a two-page article that explains these controls with some simple examples: http://aspnet.4guysfromrolla.com/articles/052103-1.aspx
I didn't find anything like DetailsView for .NET 1.x.
I'm not really sure what is happening with your code, but one thought is that the button1_click event must be causing a postback. When a postback event occurs the page_load event is fired, which would reload your listbox unless you place a If Not Me.IsPostback Then statement before your listbox loading statements in page_load:
If Not Me.IsPostback Then
Me.ListBox1.items.Clear()
Dim myConnectionAs OdbcConnection
my Connection =New OdbcCOnnection (DBConn =New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myServer;Database=ResumesDB;User=myUserassword=myPass;Option=3;")
Dim AD asNew OdbcDAtaAdapter("SELECT ResumeID, Resumes From Professions", myConnection)Dim DS asNew Dataset
AD.Fill(DS)
AD.Dispose()
Me.ListBox1.DataSource=DS
Me.ListBox1.DataTextField="Resumes"
Me.ListBox1.DataSource=DS="ResumesID"
Me.ListBox1.Databind()
End If
I think you just want the listbox to load on the first page load, not on every postback.
Also, if you use listboxes, it may be easier to use separate listboxes. So, user selects item in listbox1, then items are loaded in listbox2. I usually try to get an easy version working first.
0 comments:
Post a Comment