PC Review


Reply
Thread Tools Rating: Thread Rating: 23 votes, 3.78 average.

get datakey from datalist

 
 
Andy Sutorius
Guest
Posts: n/a
 
      3rd Mar 2005
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
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      3rd Mar 2005
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" <(E-Mail Removed)> wrote in message
news:%RIVd.31239$(E-Mail Removed)...
> 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
 
 
 
 
Andy Sutorius
Guest
Posts: n/a
 
      3rd Mar 2005
Hi Karl,

Why should it be ToInt32?

Andy


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%RIVd.31239$(E-Mail Removed)...
> > 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
 
Karl Seguin
Guest
Posts: n/a
 
      3rd Mar 2005
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" <(E-Mail Removed)> wrote in message
news:g5KVd.31243$(E-Mail Removed)...
> Hi Karl,
>
> Why should it be ToInt32?
>
> Andy
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:%RIVd.31239$(E-Mail Removed)...
> > > 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
 
Andy Sutorius
Guest
Posts: n/a
 
      3rd Mar 2005
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:(E-Mail Removed)...
> 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
 
Karl Seguin
Guest
Posts: n/a
 
      4th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:dOKVd.31247$(E-Mail Removed)...
> 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:(E-Mail Removed)...
> > 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
 
Andy Sutorius
Guest
Posts: n/a
 
      4th Mar 2005
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:%(E-Mail Removed)...
> 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
 
Karl Seguin
Guest
Posts: n/a
 
      4th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:ab%Vd.31416$(E-Mail Removed)...
> 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:%(E-Mail Removed)...
> > 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

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
Problem With DataList Datakey Anil TG Microsoft ASP .NET 2 20th Aug 2009 07:20 AM
DataList DataKey button_click assignment Problem (DataListCommandEventArgs) Jim in Arizona Microsoft ASP .NET 1 18th Sep 2006 07:23 PM
Get DataKey on RowDataBound MasterChief Microsoft ASP .NET 3 16th Feb 2006 12:03 AM
how can i get datakey value of GridView ??????? mike Microsoft ASP .NET 0 25th Nov 2005 01:06 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll Microsoft ASP .NET 8 9th Sep 2004 11:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:17 AM.