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