|
-
May 12th, 2004, 11:25 AM
#1
Thread Starter
Lively Member
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").Value = DataBinder.Eval(Me.Dsarticles.tblarticles.DefaultView(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).Row
'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").Value = DataBinder.Eval(Me.Dsarticles.tblarticles.DefaultView(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 Class
-
May 12th, 2004, 11:46 AM
#2
Junior Member
try getting .selectedindex().text property
www.mod2software.com
Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
-
May 12th, 2004, 12:40 PM
#3
Thread Starter
Lively Member
For some reason the selected index always retruns a static value, here is the error:
Index -1 is not non-negative and below total rows count.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index -1 is not non-negative and below total rows count
-
May 12th, 2004, 01:42 PM
#4
Junior Member
-1 is returned if nothing in the list is selected.
make sure something is selected before passing it along to the next process
www.mod2software.com
Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
-
May 12th, 2004, 01:45 PM
#5
Thread Starter
Lively Member
But this error comes up when I select an item. Any idea what I could be msising?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|