Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > e.Item.ItemIndex returns wrong value

Reply
Thread Tools

e.Item.ItemIndex returns wrong value

 
 
Stephan
Guest
Posts: n/a
 
      07-26-2004
Hi,

I'm working on a page with multiple Datalist-controls on it. The
problem I'm facing is that when I try to update a record, the
ItemIndex returns a value which is one lower than the Item I want to
edit, so when I update the record, the previous record is changed. I
put some code here, but not all. Adding, of
course, is no problem because then the index is set to -1. I tried to
use the DataKeyField property in my controls, but that doesn't work
either. I've the feeling that I terribly overlooking something. What
am I doing wrong?

Thx in advance

If Not Page.IsPostBack Then
BindData()
End If


Private Function BindData()
Dim dsSubDoelen As DataSet = objDoelen.SelectSTBSubDoelen("")
Dim dsDoelen As DataSet = objDoelen.SelectSTBDoelen("")
Dim dsGedrag As DataSet = objDoelen.SelectGedrag("")
Dim dsMethodiek As DataSet = objDoelen.SelectMethodiek("")

dlSTBDoelen.DataSource = dsDoelen
dlSTBDoelen.DataBind()

dlSTBSubDoelen.DataSource = dsSubDoelen
dlSTBSubDoelen.DataBind()

dlGedrag.DataSource = dsGedrag
dlGedrag.DataBind()

dlMethodiek.DataSource = dsMethodiek
dlMethodiek.DataBind()

End Function

Private Sub dlSTBSubDoelen_EditCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
dlSTBSubDoelen.EditCommand
Mode.Value = "Edit"
dlSTBSubDoelen.EditItemIndex = CInt(e.Item.ItemIndex) <--
return a value which is one to low
BindData()
End Sub
 
Reply With Quote
 
 
 
 
chanmmn
Guest
Posts: n/a
 
      07-26-2004
Just don't forget your array index start from 0 not 1. Hope that might help
you.

chanmm

"Stephan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I'm working on a page with multiple Datalist-controls on it. The
> problem I'm facing is that when I try to update a record, the
> ItemIndex returns a value which is one lower than the Item I want to
> edit, so when I update the record, the previous record is changed. I
> put some code here, but not all. Adding, of
> course, is no problem because then the index is set to -1. I tried to
> use the DataKeyField property in my controls, but that doesn't work
> either. I've the feeling that I terribly overlooking something. What
> am I doing wrong?
>
> Thx in advance
>
> If Not Page.IsPostBack Then
> BindData()
> End If
>
>
> Private Function BindData()
> Dim dsSubDoelen As DataSet = objDoelen.SelectSTBSubDoelen("")
> Dim dsDoelen As DataSet = objDoelen.SelectSTBDoelen("")
> Dim dsGedrag As DataSet = objDoelen.SelectGedrag("")
> Dim dsMethodiek As DataSet = objDoelen.SelectMethodiek("")
>
> dlSTBDoelen.DataSource = dsDoelen
> dlSTBDoelen.DataBind()
>
> dlSTBSubDoelen.DataSource = dsSubDoelen
> dlSTBSubDoelen.DataBind()
>
> dlGedrag.DataSource = dsGedrag
> dlGedrag.DataBind()
>
> dlMethodiek.DataSource = dsMethodiek
> dlMethodiek.DataBind()
>
> End Function
>
> Private Sub dlSTBSubDoelen_EditCommand(ByVal source As Object,
> ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
> dlSTBSubDoelen.EditCommand
> Mode.Value = "Edit"
> dlSTBSubDoelen.EditItemIndex = CInt(e.Item.ItemIndex) <--
> return a value which is one to low
> BindData()
> End Sub



 
Reply With Quote
 
 
 
 
Stephan Bussing
Guest
Posts: n/a
 
      07-26-2004
Hi,

Thx for your reply, but sorry that I forgot to mention. I know that
ItemIndex starts at 0. So what I tried is to add 1 to the index, but
then not the current, but the next row is in editmode.

I tried: dlSTBDoelen.EditItemIndex = CInt(e.Item.ItemIndex) + 1

I figured out that this caused the next row in editmode problem. So
maybe I'd better add +1 when updating the record. That of course should
do the trick. I'm only wondering how I can be sure that the right ID is
used. I mean what does the purpose does the DataKeyField of the Datalist
serve. How can I use it in my code. When I update I still user de
EditItemIndex which in my case has a wrong value.

Anyone?



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Stephan Bussing
Guest
Posts: n/a
 
      07-26-2004
I actually forgot to mention that I tried several things, ie adding 1 to
the EditItemIndex when updating, this is not a good thing since the
recordId doesn't necessarely has to follow the index. I also tried to
put the data in a labelcontrol and before updating, reading it's value
through the findControl-statement. This works best, but I just want to
know why the e.Item.ItemIndex method doesn't work or how I can use the
DataKeyField properly so I always have the right ID for an update.

Thx


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorted Returns List and Reversed Returns Iterator ++imanshu Python 7 08-23-2008 04:25 AM
createImage sometime returns null and sometime returns non-null. vizlab Java 3 10-17-2007 11:21 AM
ASP.NET User.Identity.Name returns wrong value? JohnH. ASP .Net Security 5 03-22-2005 09:09 PM
New window.name value doesn't stick. Old value returns unless the window is refreshed Diana Javascript 1 04-06-2004 12:09 AM
Checkbox returns wrong value when disabled Paul ASP .Net 1 08-27-2003 11:57 AM



Advertisments