473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1315
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Smith | last post by:
Hi friends Can anybody tell me where to use datagrid and where to use datalist. Or explain Different between DataGrid and DataList. Regards, Alex
2
by: Art Kedroski | last post by:
We are using .NET validators on most of our aspx pages. When the validator is contained within a datalist (i.e. the EditItemTemplate) the WebUIValidation.js file location tag is not rendered on...
1
by: Jurjen de Groot | last post by:
I have an ArrayList with NewsItem objects wich have properties 'newsDate' and 'newsText' I can off course bind the ArrayList to the Datalist, but how do I procede from there ? In the...
5
by: Martman | last post by:
First here is my goal: When a datalist is rendered to a page and you use the <itemtemplate> the datalist automatically prints a <tr> <td> start and end tags. Now this may not be too bad but I...
3
by: GD | last post by:
I'm using a DataList and a Repeater (nested in the DataList) to display a list of "Chapters" and "Documents" within the Chapters. <asp:DataList ID="dlChapter" Runat="server" RepeatColumns="2"...
1
by: Jules | last post by:
We have a problem setting, actually resetting, the SelectedItemTemplate of a DataList control. Below is the ObjectDataSource and the DataList in .ASPX: <asp:ObjectDataSource ID="mySource"...
1
by: studen771 | last post by:
Thanks in advance to anyone who can help :) I have my datalist bound to a normal, single dimension string array (with three elements) as its data source. In the scripting for the datagrid, I have...
2
by: sck10 | last post by:
Hello, I am populating a DataList with data from a stored procedure. What I am trying to do is change the color based on the one of the values that the stored procedure sends. When I try to...
0
by: Andy B | last post by:
I have the following code. Is there another way to simplify it but get the exact same thing done? It is a DataList that gets the nodes from a SiteMapDataSource and displays them on the page as a...
4
by: Peter | last post by:
I have a DataList and each item in the datalist has an imge, I want to change the datalist item image on the client side when user clicks a button. How would I do that with JavaScript, does anyone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.