tmccrank
asked on
How to increment an Integer variable across methods
Hi,
How can I increment "i" with every iteration of the ItemDataBound event?
Private Sub BindData()
'retrieve DataSet
Dim dsQuestions As DataSet = Me.propQuestionsData
'bind the questions Repeater to dsQuestions DataSet
rptQuestions.DataSource = dsQuestions
rptQuestions.DataBind()
End Sub
Public Sub rptQuestions_ItemDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls. RepeaterIt emEventArg s) Handles rptQuestions.ItemDataBound
'retrieve DataSet from Session variable
Dim dsAnswers As DataSet = CType(Session("dsAnswers") , DataSet)
Dim lt As ListItemType = e.Item.ItemType
If lt = ListItemType.Item Or lt = ListItemType.AlternatingIt em Then
'find the RadiobuttonList control
Dim rblAnswers As RadioButtonList = CType(e.Item.FindControl(" rblAnswers "), RadioButtonList)
'if the RBL control exists, then
If Not rblAnswers Is Nothing Then
Dim dv As New DataView(dsAnswers.Tables( 0))
Dim i As Integer = CInt(dsAnswers.Tables(0).R ows(0).Ite m(2))
dv.RowFilter = "QuestionsID =" & i <-- THIS IS WHERE I NEED "i" TO INCREMENT
rblAnswers.DataSource = dv
rblAnswers.DataTextField = "Answers"
rblAnswers.DataValueField = "AnswersID"
rblAnswers.DataBind()
End If
End If
End Sub
Thanks,
Jens
How can I increment "i" with every iteration of the ItemDataBound event?
Private Sub BindData()
'retrieve DataSet
Dim dsQuestions As DataSet = Me.propQuestionsData
'bind the questions Repeater to dsQuestions DataSet
rptQuestions.DataSource = dsQuestions
rptQuestions.DataBind()
End Sub
Public Sub rptQuestions_ItemDataBound
'retrieve DataSet from Session variable
Dim dsAnswers As DataSet = CType(Session("dsAnswers")
Dim lt As ListItemType = e.Item.ItemType
If lt = ListItemType.Item Or lt = ListItemType.AlternatingIt
'find the RadiobuttonList control
Dim rblAnswers As RadioButtonList = CType(e.Item.FindControl("
'if the RBL control exists, then
If Not rblAnswers Is Nothing Then
Dim dv As New DataView(dsAnswers.Tables(
Dim i As Integer = CInt(dsAnswers.Tables(0).R
dv.RowFilter = "QuestionsID =" & i <-- THIS IS WHERE I NEED "i" TO INCREMENT
rblAnswers.DataSource = dv
rblAnswers.DataTextField = "Answers"
rblAnswers.DataValueField = "AnswersID"
rblAnswers.DataBind()
End If
End If
End Sub
Thanks,
Jens
You could set up a hidden label with ViewState enabled. Add to the existing value of the label and reassign the new value when you are done incrementing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you should be able to declare i outside of the method in the class delcaration and then just increment it.
public class MyPage : System.Web.UI.Page
{
int i;
ItemDataboundmethod()
{
i++;
}
}
It's C# but hopefully you get the idea
public class MyPage : System.Web.UI.Page
{
int i;
ItemDataboundmethod()
{
i++;
}
}
It's C# but hopefully you get the idea
ASKER
Justin,
Thanks, that's the ticket. You're right about the sequential, incrementing IDs in SQL Server, this takes care of that without having to worry about missing IDs.
Jens
Thanks, that's the ticket. You're right about the sequential, incrementing IDs in SQL Server, this takes care of that without having to worry about missing IDs.
Jens