PC Review Forums Newsgroups Microsoft DotNet Microsoft ASP .NET get datakey from datalist

Reply

get datakey from datalist

 
Thread Tools Rate Thread
Old 03-03-2005, 06:39 PM   #1
Andy Sutorius
Guest
 
Posts: n/a
Default get datakey from datalist


Hi,

I have a datalist with a asp:button. I have onitemcommand firing when the
button is clicked. I am attempting to get the datakey of the button that was
clicked. I can retrieve a specific datakey with the following: int
intProductID = Convert.ToInt16(dlstProducts.DataKeys[0]) but how do I
retrieve the datakey of the button clicked? I have tried this
unsuccessfully: int intProductID = Convert.ToInt16(dlstProducts.DataKeys[e])

Thanks,

Andy


  Reply With Quote
Old 03-03-2005, 07:56 PM   #2
Karl Seguin
Guest
 
Posts: n/a
Default Re: get datakey from datalist

use e.Item.ItemIndex to get the index of the item

dlstProducts.DataKeys[e.Item.ItemIndex]

also, any particular reason you are using ToInt16 instead of 32?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Andy Sutorius" <andy@sutorius.com> wrote in message
news:%RIVd.31239$Yf5.3109964@twister.southeast.rr.com...
> Hi,
>
> I have a datalist with a asp:button. I have onitemcommand firing when the
> button is clicked. I am attempting to get the datakey of the button that

was
> clicked. I can retrieve a specific datakey with the following: int
> intProductID = Convert.ToInt16(dlstProducts.DataKeys[0]) but how do I
> retrieve the datakey of the button clicked? I have tried this
> unsuccessfully: int intProductID =

Convert.ToInt16(dlstProducts.DataKeys[e])
>
> Thanks,
>
> Andy
>
>



  Reply With Quote
Old 03-03-2005, 08:04 PM   #3
Andy Sutorius
Guest
 
Posts: n/a
Default Re: get datakey from datalist

Hi Karl,

Why should it be ToInt32?

Andy


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OJ0Y1sCIFHA.156@TK2MSFTNGP10.phx.gbl...
> use e.Item.ItemIndex to get the index of the item
>
> dlstProducts.DataKeys[e.Item.ItemIndex]
>
> also, any particular reason you are using ToInt16 instead of 32?
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Andy Sutorius" <andy@sutorius.com> wrote in message
> news:%RIVd.31239$Yf5.3109964@twister.southeast.rr.com...
> > Hi,
> >
> > I have a datalist with a asp:button. I have onitemcommand firing when

the
> > button is clicked. I am attempting to get the datakey of the button that

> was
> > clicked. I can retrieve a specific datakey with the following: int
> > intProductID = Convert.ToInt16(dlstProducts.DataKeys[0]) but how do I
> > retrieve the datakey of the button clicked? I have tried this
> > unsuccessfully: int intProductID =

> Convert.ToInt16(dlstProducts.DataKeys[e])
> >
> > Thanks,
> >
> > Andy
> >
> >

>
>



  Reply With Quote
Old 03-03-2005, 08:47 PM   #4
Karl Seguin
Guest
 
Posts: n/a
Default Re: get datakey from datalist

in my opinion yes...assuming ur developing on 32-bit system...

a c# int (or vb.net integer) maps to Int32 on a 32bit system so it's what
you'll get the most performance out of...

Int16 is only useful when you have very large chunks of data (large int
arrays) and you want to consume less space....

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Andy Sutorius" <andy@sutorius.com> wrote in message
news:g5KVd.31243$Yf5.3114710@twister.southeast.rr.com...
> Hi Karl,
>
> Why should it be ToInt32?
>
> Andy
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:OJ0Y1sCIFHA.156@TK2MSFTNGP10.phx.gbl...
> > use e.Item.ItemIndex to get the index of the item
> >
> > dlstProducts.DataKeys[e.Item.ItemIndex]
> >
> > also, any particular reason you are using ToInt16 instead of 32?
> >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/ - New and Improved (yes, the popup is
> > annoying)
> > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> > come!)
> > "Andy Sutorius" <andy@sutorius.com> wrote in message
> > news:%RIVd.31239$Yf5.3109964@twister.southeast.rr.com...
> > > Hi,
> > >
> > > I have a datalist with a asp:button. I have onitemcommand firing when

> the
> > > button is clicked. I am attempting to get the datakey of the button

that
> > was
> > > clicked. I can retrieve a specific datakey with the following: int
> > > intProductID = Convert.ToInt16(dlstProducts.DataKeys[0]) but how do I
> > > retrieve the datakey of the button clicked? I have tried this
> > > unsuccessfully: int intProductID =

> > Convert.ToInt16(dlstProducts.DataKeys[e])
> > >
> > > Thanks,
> > >
> > > Andy
> > >
> > >

> >
> >

>
>



  Reply With Quote
Old 03-03-2005, 08:52 PM   #5
Andy Sutorius
Guest
 
Posts: n/a
Default Re: get datakey from datalist

Karl,

After putting in the snippet of code I receive the following error: "Object
reference not set to an instance of an object."

Line 63: // Obtain current user's shopping cart ID
Line 64: String cartId = cart.GetShoppingCartId();
Line 65:
Line 66: // Add Product Item to Cart
Line 67: int intProductID =
Convert.ToInt32(dlstProducts.DataKeys[e.Item.ItemIndex]);


Source File: c:\inetpub\wwwroot\psyche\boutique\default.aspx.cs Line: 65

I'm stumped why the Convert statement isn't resolving this error.

Andy



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OJ0Y1sCIFHA.156@TK2MSFTNGP10.phx.gbl...
> use e.Item.ItemIndex to get the index of the item
>
> dlstProducts.DataKeys[e.Item.ItemIndex]
>
> also, any particular reason you are using ToInt16 instead of 32?
>
> Karl
>



  Reply With Quote
Old 04-03-2005, 01:27 PM   #6
Karl Seguin
Guest
 
Posts: n/a
Default Re: get datakey from datalist

A little hard to troubleshoot since line 65 appears blank

there are only 4 possibilities:
cart is null
dlstProducts is null
e is null
e.Item is null

it's imossible for me to tell you which it is with what you've given
me...try stepping through your code and put a watch on each of those
items...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Andy Sutorius" <andy@sutorius.com> wrote in message
news:dOKVd.31247$Yf5.3117224@twister.southeast.rr.com...
> Karl,
>
> After putting in the snippet of code I receive the following error:

"Object
> reference not set to an instance of an object."
>
> Line 63: // Obtain current user's shopping cart ID
> Line 64: String cartId = cart.GetShoppingCartId();
> Line 65:
> Line 66: // Add Product Item to Cart
> Line 67: int intProductID =
> Convert.ToInt32(dlstProducts.DataKeys[e.Item.ItemIndex]);
>
>
> Source File: c:\inetpub\wwwroot\psyche\boutique\default.aspx.cs Line:

65
>
> I'm stumped why the Convert statement isn't resolving this error.
>
> Andy
>
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:OJ0Y1sCIFHA.156@TK2MSFTNGP10.phx.gbl...
> > use e.Item.ItemIndex to get the index of the item
> >
> > dlstProducts.DataKeys[e.Item.ItemIndex]
> >
> > also, any particular reason you are using ToInt16 instead of 32?
> >
> > Karl
> >

>
>



  Reply With Quote
Old 04-03-2005, 03:31 PM   #7
Andy Sutorius
Guest
 
Posts: n/a
Default Re: get datakey from datalist

Karl,

After a good nights sleep I stepped through and it worked perfectly. I must
have forgotten to rebuild or something. Sorry to lead you on a wild goose
chase.

Thanks for your help!

Andy


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23cFNM3LIFHA.3608@TK2MSFTNGP14.phx.gbl...
> A little hard to troubleshoot since line 65 appears blank
>
> there are only 4 possibilities:
> cart is null
> dlstProducts is null
> e is null
> e.Item is null
>
> it's imossible for me to tell you which it is with what you've given
> me...try stepping through your code and put a watch on each of those
> items...
>
> Karl



  Reply With Quote
Old 04-03-2005, 04:43 PM   #8
Karl Seguin
Guest
 
Posts: n/a
Default Re: get datakey from datalist

glad to hear it!

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Andy Sutorius" <andy@sutorius.com> wrote in message
news:ab%Vd.31416$Yf5.3213416@twister.southeast.rr.com...
> Karl,
>
> After a good nights sleep I stepped through and it worked perfectly. I

must
> have forgotten to rebuild or something. Sorry to lead you on a wild goose
> chase.
>
> Thanks for your help!
>
> Andy
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23cFNM3LIFHA.3608@TK2MSFTNGP14.phx.gbl...
> > A little hard to troubleshoot since line 65 appears blank
> >
> > there are only 4 possibilities:
> > cart is null
> > dlstProducts is null
> > e is null
> > e.Item is null
> >
> > it's imossible for me to tell you which it is with what you've given
> > me...try stepping through your code and put a watch on each of those
> > items...
> >
> > Karl

>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off