468,133 Members | 1,474 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

DataList Issues

I'm a bit confused by the datalist. I can put an item in the datalist in editmode by the following

dtlBooks.EditItemIndex = e.Item.ItemInde
BindBooks(

This works great, the problem is when I bind the books if less or more books get returned the ItemIndex points to a different book - so the user gets the wrong one in editmode

Is there a way to stop this? If the user deletes it's even worse :)
Nov 18 '05 #1
5 1179
Hi,

the index points to certain item in the data source (count of data items) so
basically if the list of item changes (starting from beginning), it will
select different one. So question is that why does the list change between
rebindings and do you get the index corrently (you seem to take it from
EditCommand event handler?). And do you have ViewState enabled?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Ian O'Rourke" <an*******@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
I'm a bit confused by the datalist. I can put an item in the datalist in editmode by the following:
dtlBooks.EditItemIndex = e.Item.ItemIndex
BindBooks()

This works great, the problem is when I bind the books if less or more books get returned the ItemIndex points to a different book - so the user
gets the wrong one in editmode?
Is there a way to stop this? If the user deletes it's even worse :)

Nov 18 '05 #2
I have handlers for all my events. I have viewstate enabled

If we take the simple example - the EditCommandEvent

Sub BindPorts(

colBooks = Port.GetBooksByPortNameFilter(txtBookFilter.Text
dtlBooks.DataSource = colBook
dtlBooks.DataBind(

End Su

Private Sub dtlPorts_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles dtlPorts.EditComman

dtlBooks.EditItemIndex = e.Item.ItemInde
BindBooks(

End Su

As you can seen I am re-binding after every EditCommand - this is because if I do not do this I have to press my EditCommand button twice to get it to work (it triggers the Event the first time, but not the second, and then goes into Edit Mode on the DataList). I'm not sure why I need the re-binding as I have viewstate on

So, since I'm rebinding, if a user has deleted a book, the index the user selected will be wrong - and the user actually edits the book next in the list (than the one he selected).

Not sure how to get around it? I could save the Collection (that is assigned to the DataList) in session state, but this seems a bit much. Or I could get the Commands working with just viewstate and no re-binding

But as long as I'm re-binding there is going to be this problem?

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #3
Wasn't watching what I was doing - wherever you see Port, change it to Book :) It's not like that in the application.

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #4
For Clarity Code is

If we take the simple example - the EditCommandEvent

Sub BindBooks(

colBooks = Book.GetBooksByBookNameFilter(txtBookFilter.Text
dtlBooks.DataSource = colBook
dtlBooks.DataBind(

End Su

Private Sub dtlBooks_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles dtlBooks.EditComman

dtlBooks.EditItemIndex = e.Item.ItemInde
BindBooks(

End Su

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #5
When you change to edit mode, rebinding is always needed, that's by design
(like you need to when sorting or paging with DataGrid). One solution in
delete case is to reset the index (after user has deleted an item), or get
the datasource beforehand and check that is the (item count in data source -
1) less than current EditItemIndex, if it is resetr the counter or set it to
the (item count -1)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Fandomlife" <ian.orourke@-NOSPAM-fandomlife.net> wrote in message
news:u2****************@tk2msftngp13.phx.gbl...
I have handlers for all my events. I have viewstate enabled.

If we take the simple example - the EditCommandEvent:

Sub BindPorts()

colBooks = Port.GetBooksByPortNameFilter(txtBookFilter.Text)
dtlBooks.DataSource = colBooks
dtlBooks.DataBind()

End Sub
Private Sub dtlPorts_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
dtlPorts.EditCommand

dtlBooks.EditItemIndex = e.Item.ItemIndex
BindBooks()

End Sub

As you can seen I am re-binding after every EditCommand - this is because if
I do not do this I have to press my EditCommand button twice to get it to
work (it triggers the Event the first time, but not the second, and then
goes into Edit Mode on the DataList). I'm not sure why I need the re-binding
as I have viewstate on.

So, since I'm rebinding, if a user has deleted a book, the index the user
selected will be wrong - and the user actually edits the book next in the
list (than the one he selected).

Not sure how to get around it? I could save the Collection (that is assigned
to the DataList) in session state, but this seems a bit much. Or I could get
the Commands working with just viewstate and no re-binding.

But as long as I'm re-binding there is going to be this problem?

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest
Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Alex Smith | last post: by
2 posts views Thread by Art Kedroski | last post: by
1 post views Thread by Jurjen de Groot | last post: by
5 posts views Thread by Martman | last post: by
3 posts views Thread by GD | last post: by
1 post views Thread by studen771 | last post: by
2 posts views Thread by sck10 | last post: by
reply views Thread by Andy B | last post: by
4 posts views Thread by Peter | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.