By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,528 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

ASP .NET webpage won't accept changes

P: n/a
I have a dropDownList with a selectedIndexChanged event which populates a
textBox. The dropDownList is being populated by a dataSet. Problem is when
you select an entry from the list, the whole form refreshes and it just goes
back to the top of the dataSet. Any ideas?
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
OK I resolved the original problem by setting If Not IsPostBack in the
page_Load event which is where the dataset is being loaded. Now however I
get an exception when I change the value of the dropDownList:

System.IndexOutOfRangeException: Index 0 is not non-negative and below total
rows count

This was returning the correct data when it was refreshing the dataSet, just
for the wrong user selected.
Nov 21 '05 #2

P: n/a
I apologize to so many changes to the original post but, here's what I've
found so far. Apparently, the dropDownList Index_change event is triggering
a refresh of the form. Now that the form isn't loading the dataset because
of the Not isPostBack, it's just emptying the dataSet so I'm doing an index
lookup on an empty set. Is this the way this is supposed to work? If not,
why am I losing my dataSet? I'm calling a DataBind within the Page_Load.
Nov 21 '05 #3

P: n/a
Because HTTP is a connectionelss protocol. Once the page is served up, the
Page object is destroyed. When the client makes another request (e.g. a
postback), a new Page object is created and the code is executed - but
because it's a brand new instance of an object, all of its local variables
are initialized to their defaults.

Don't make the mistake of thinking of the page as you would a windows form
where you have one instance of an object the whole time. Web programming is
completely different.

"rr****@800mcmahan.com" <rr*****************@discussions.microsoft.com>
wrote in message news:9D**********************************@microsof t.com...
I apologize to so many changes to the original post but, here's what I've
found so far. Apparently, the dropDownList Index_change event is triggering a refresh of the form. Now that the form isn't loading the dataset because of the Not isPostBack, it's just emptying the dataSet so I'm doing an index lookup on an empty set. Is this the way this is supposed to work? If not, why am I losing my dataSet? I'm calling a DataBind within the Page_Load.

Nov 21 '05 #4

P: n/a
Roman,

I think that this simple sample that I just made can help you how to handle
your problem.

\\\
Private Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet
If Not IsPostBack Then
ds = New Dataset
Dim dt As New DataTable
dt.Columns.Add("mycolumn1")
dt.Columns.Add("mycolumn2")
dt.Rows.Add(dt.NewRow)
dt.Rows.Add(dt.NewRow)
dt.Rows(0)(0) = "Een"
dt.Rows(0)(1) = "Roman"
dt.Rows(1)(0) = "Twee"
dt.Rows(1)(1) = "Cor"
Session.Item("ds") = ds
ds.Tables.Add(dt)
DropDownList1.AutoPostBack = True
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataTextField = "mycolumn1"
DropDownList1.DataValueField = "mycolumn2"
DropDownList1.DataBind()
Else
ds = DirectCast(Session.Item("ds"), DataSet)
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal _
sender As System.Object, ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Me.TextBox1.Text = Me.DropDownList1.SelectedValue.ToString
End Sub
///

I hope this helps?

Cor
"rr****@800mcmahan.com" <rr*****************@discussions.microsoft.com> I
apologize to so many changes to the original post but, here's what I've
found so far. Apparently, the dropDownList Index_change event is
triggering
a refresh of the form. Now that the form isn't loading the dataset
because
of the Not isPostBack, it's just emptying the dataSet so I'm doing an
index
lookup on an empty set. Is this the way this is supposed to work? If
not,
why am I losing my dataSet? I'm calling a DataBind within the Page_Load.

Nov 21 '05 #5

P: n/a
Thank you so much Cor, once again you've helped me greatly.

"Cor Ligthert" wrote:
Roman,

I think that this simple sample that I just made can help you how to handle
your problem.

\\\
Private Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet
If Not IsPostBack Then
ds = New Dataset
Dim dt As New DataTable
dt.Columns.Add("mycolumn1")
dt.Columns.Add("mycolumn2")
dt.Rows.Add(dt.NewRow)
dt.Rows.Add(dt.NewRow)
dt.Rows(0)(0) = "Een"
dt.Rows(0)(1) = "Roman"
dt.Rows(1)(0) = "Twee"
dt.Rows(1)(1) = "Cor"
Session.Item("ds") = ds
ds.Tables.Add(dt)
DropDownList1.AutoPostBack = True
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataTextField = "mycolumn1"
DropDownList1.DataValueField = "mycolumn2"
DropDownList1.DataBind()
Else
ds = DirectCast(Session.Item("ds"), DataSet)
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal _
sender As System.Object, ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Me.TextBox1.Text = Me.DropDownList1.SelectedValue.ToString
End Sub
///

I hope this helps?

Cor
"rr****@800mcmahan.com" <rr*****************@discussions.microsoft.com> I
apologize to so many changes to the original post but, here's what I've
found so far. Apparently, the dropDownList Index_change event is
triggering
a refresh of the form. Now that the form isn't loading the dataset
because
of the Not isPostBack, it's just emptying the dataSet so I'm doing an
index
lookup on an empty set. Is this the way this is supposed to work? If
not,
why am I losing my dataSet? I'm calling a DataBind within the Page_Load.


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.