PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ASP .NET
get datakey from datalist
Forums
Newsgroups
Microsoft DotNet
Microsoft ASP .NET
get datakey from datalist
![]() |
get datakey from datalist |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 > > > > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 > > > > > > > > > > > > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
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 > > > > |
|
|
|
#7 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#8 |
|
Guest
Posts: n/a
|
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 > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


