473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Listbox- Record Select

Hi,

This code works fine, but part of it is really bugging me. Basically this code changes the page to reflect the item slected in a list box, the only problem is I have to first assign:

Me.Articlelist.SelectedValue.ToString

to the text property of a label and then refer to this from the line me.position = otherwise it doesn't work. I have tried converting the string but it refuses to work and I just get an error saying 'Input string was not in a correct format'. Does anyone know why this is happening?

Public Class WebForm8

Inherits System.Web.UI.Page
Public Position As Integer

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
Me.Articlelist.AutoPostBack = True
If Me.IsPostBack Then
Me.Dsarticles = CType(Viewstate("Dsarticles"), DataSet)
Me.Dsphotos = CType(Viewstate("Dsphotos"), DataSet)
Me.Position = CType(Viewstate("Position"), Integer)
Else

Me.Daarticles.Fill(Me.Dsarticles.tblarticles)
Daphotos.SelectCommand.Parameters("@article_ID").V alue = DataBinder.Eval(Me.Dsarticles.tblarticles.DefaultV iew(Position).Row, "article_ID")
Me.Daphotos.Fill(Me.Dsphotos.tblphotos)
viewstate("Dsarticles") = Me.Dsarticles
viewstate("Dsphotos") = Me.Dsphotos
viewstate("Position") = 0
End If

Me.DataBind()

End Sub
Private Sub Page_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DataBinding
Dim dr As DataRow
dr = Me.Dsarticles.tblarticles.DefaultView(Position).Ro w

'Me.lbArticle_Name.Text = DataBinder.Eval(dr, "Article_Name")
Me.lbarticle_text.Text = DataBinder.Eval(dr, "Article_text")
Me.lbWritten_By.Text = DataBinder.Eval(dr, "Written_By")
Me.lbarticle_date.Text = DataBinder.Eval(dr, "Article_Date")
Me.Label1.Text = Me.Articlelist.SelectedValue.ToString

End Sub

Private Sub Articlelist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Articlelist.SelectedIndexChanged

If Me.Position <= Me.Dsarticles.tblarticles.Count - 1 Then
Me.Position = Me.Label1.Text - 1
Me.Dsphotos.Clear()
Daphotos.SelectCommand.Parameters("@article_ID").V alue = DataBinder.Eval(Me.Dsarticles.tblarticles.DefaultV iew(Position).Row, "article_ID")
Me.Daphotos.Fill(Me.Dsphotos.tblphotos)
viewstate("Dsphotos") = Me.Dsphotos
viewstate("Position") = Me.Position
Me.DataBind()
End If

End Sub

End Clas

Nov 20 '05 #1
0 795

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
5
by: Bill | last post by:
I have have two list boxes. One is a listing of all possible variables. We'll call this listbox A. The other is a listing of all the selected variables. We'll call this listbox B. If a person...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
3
by: rn5a | last post by:
I am not very sure whether I should have continued with my earlier thread or started a new thread whose subject matter was somewhat similar to the subject matter in this thread. Anyway after much...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.