Home
Get Started
Learn
Downloads
AJAX
MVC
Community
Wiki
Forums
Sign in
|
Join
Home
›
ASP.NET Forums
›
Search
Search
You searched for the word(s): userid:639116
More Search Options
RSS Available
Matching Posts
DataList DataKey index out of range
I'm trying to iterate though a DataList to grab the DataKey values. I have used code very similar to that pasted below in an ItemCommand event but I can't seem to get it to work on a ButtonClick event. I'm getting an Index out of range error. protected void UpdateButton_Click( object sender, EventArgs e) { // Get the data key value int photoId = 0; foreach (DataListItem item in PhotoList.Items) { if (item.ItemIndex > -1) { photoId = Convert.ToInt32(PhotoList.DataKeys[item.ItemIndex
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: DataList DataKey index out of range
There is a single DataKey: DataKey="SlideID" With respect to the value of item.ItemIndex, I intended it to represent a row in the DataTable with PhotoID being the primary key/DataKey. I've always been a bit unclear on this. It seems to me that the ItemIndex should be exactly that - the index value [0] to [n] rather than the DataKey value, but apparently not based on all the syntax references I've looked at. As mentioned, I can get the DataKey value from an item command by means
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: DataList DataKey index out of range
Don't believe it will. e in this case refers to the ButtonClick event args
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: DataList DataKey index out of range
Interesting. Whether I put string debug = (PhotoList.DataKeys[0]).ToString(); inside or outside of the foreach loop it throws the index out of range error. But I know I have a good data table. I have no problem getting PhotoID from the ItemDataBound event with photoId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "PhotoID"));
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: DataList DataKey index out of range
Thanks to you and tusharrs for the tip. In the DataList I set DataKey="Foo" - which of course is not in the datasource - and the page did not throw a data binding error. This is just a bit weird because everthing else works fine. How much more fun could I be having on a Saturday night?
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: DataList DataKey index out of range
Ahhhhhh!!! It is DataKeyField="PhotoID" _not_ DataKey="PhotoID"
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: DataList DataKey index out of range
Works as intended now. For the record (and to solicit any suggestions for improving it) here's the button click event code: protected void UpdateButton_Click( object sender, EventArgs e) { int index = 0; int photoId = 0; foreach (DataListItem item in SlideList.Items) { if (item.ItemIndex > -1) { CheckBox checkActive= (CheckBox)item.FindControl( "IsActive" ); if (checkActive!= null ) { if (checkActive.Checked) { index = Convert.ToInt32(item.ItemIndex); photoId = Convert.ToInt32(SlideList
Posted to
Data Presentation Controls
(Forum)
by
GDB
on 11/28/2009
Re: Local website: use directory other than INETPUB
OK, I overstated the issue. More of a minor annoyance than a major one. Got lazy with the one click new website thing. Went back to the old fashioned way which is to create a folder for the website files, create a new virtual folder in IIS that points to my new folder, then convert the virtual folder to an application, then in VS open the website in the file system. Adds about a minute to the effort and don’t do it that often anyway. Thanks.
Posted to
Visual Studio 2008
(Forum)
by
GDB
on 11/23/2009
Local website: use directory other than INETPUB
This falls under the category of major annoyance. I have always located the website files in a directory other than inetpub, specifically on a different drive for ease of backup. I don't remember how I set VS up that way but whenever I created a new website the stub files were created in my preferred directory. I changed something somewhere along the way and now I can't seem to get this to work. Now when I set up a new site at http://localhost/ the stub files are created in the inetpub directory
Posted to
Visual Studio 2008
(Forum)
by
GDB
on 11/20/2009
Re: SqlSiteMapProvider: database prep to support SQL cache dependencies
Thangs Jian. I'm using 2008 ... always try to be on the latest version so as to stay ahead of my competency. I have the poll time set to 5000 (web.config code pasted below). I made a test change to the database about 5 minutes ago and the menu has yet to refresh. Any other changes I make are reflected instantly so it's not that the page is being cached somewhere. I made a small change in web.config and uploaded the file after which the menu changes were reflected almost instantly. <caching>
Posted to
SQL Server, SQL Server Express, and SqlDataSource Control
(Forum)
by
GDB
on 11/3/2009
Page 1 of 24 (236 items) 1
2
3
4
5
Next >
...
Last »
TechNet Edge:
Check out how Dolly Parton uses IE8 and Web slices!!!
Silverlight:
A Silverlight HVP Update
Channel 9:
Channel 9 Live at PDC09: This Week on Channel 9 - PDC09 Daily Show Edition Day 1
Channel 9:
Maria Klawe: Scholar, Scientist and Microsoft Board Member
Channel 10:
Play the Bing Sherlock Holmes Game
Channel 9:
Channel 9 Live at PDC09: Loic Le Meur
Channel 10:
How to Delete Jump List Items
Channel 10:
Roll Back to Classic Network Indicator in Win7
Channel 9:
Jafar Husain: Silverlight Toolkit and Rx, Part 2
Channel 9:
Ping 42: Is Microsoft cool? Photo DNA, Win7 tool, 10k MIX contest
Channel 9:
Jafar Husain: Silverlight Toolkit and Rx, Part 1
Channel 9:
Francesco Logozzo - Static Checking with Code Contracts for .NET
Channel 9:
Channel 9 Live at PDC09: Doug McCuistion, NASA
TechNet Edge:
System Center Operations Manager 2007 R2 – Service Level Dashboard part 3: Configuration
Channel 9:
Reading Debate with Bill Buxton
Channel 10:
Reading Debate with Bill Buxton
WindowsClient:
Build WPF Data Controls for Outlook Addins Easily with VS2010
Channel 9:
Channel 9 Live at PDC09: .Net Rocks Part 2
Channel 9:
Channel 9 Live at PDC09: .Net Rocks Part 1
Channel 9:
Channel 9 Live at PDC09: Wei Zhu (Facebook)
Microsoft Communities
ASP.NET
Channel 8
Channel 9
Channel 10
IIS.NET
Silverlight
TechNet Edge
WindowsClient
Mix Online