473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GridView & DataKeyNames

I've recently switched from using a DataGrid component to a GridView and now
run in to some problems.

My ambition is easy; first show a list of users in a GridView component and
for each row in the grid have a SelectButton on it.

At the bottom I show how I'm trying to do it in the GridView (and with some
minor changes the code functioned with the older component DataGrid). The
first time I see the page I can see my users, but any attempt to choose a
user resolves in the following error message "Index was outside the bounds
of the array."
I seems to me that the keys dissapear and maybe one solution could be that
recreate the list of users each time the page is loaded - but that is a
solution I'm not interested in.
As standard the SelectCommand returns the row index of the row that was
selected. Could this been changed so it returns a unique id instead?

My quesitons is;

Q1) Is it possible to use the GridView in the same way I did with DataGrid?
Q2) Is it possible to use DataKey together with my own class as the
DataSource?
Q3) How can I use a CommandButton to create my own SelectCommand

Thanks

Robert Warnestam
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Get a list of all users. A user is an instant of the class TapUser
TapUser[] users = TapUser.GetAllUsers();
// Set the datasource and the primary key
// The class TapUser has a property called UserID, this will function as our
key
gvUser.DataSource = users;
string[] keys = new string[1] {"UserID"};
// Bind the grid
gvUser.DataBind();
gvUser.SelectedIndex = 0;
}
}

Nov 18 '05 #1
0 2451

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a...
1
by: Raja | last post by:
Hi Everybody Just playing with ObjectDataSource and noticed the following. I have a Gridview which binds to a ObjectDataSource. ObjectDataSource gets data from a typed dataset created with VWD. In...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
6
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In...
0
by: trint | last post by:
I hope I can explain this clearly enough to get help. I have three gridviews that need to work from each other to display like a java verticle menu (just in the way it appears). GridView1 is...
3
by: shapper | last post by:
Hello, I need to loop though each row in a GridView and if the checkbox is a Template Field is checked I want to display the value of an invisible column named "LevelName". I tried everything...
4
by: =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post by:
I setup a simple gridview as a utility just to do some updates, nothing fancy just wanted easy UI to make updates. When I select ‘Edit’, I get the fields I want to edit. I edit them and click...
2
by: rgparkins | last post by:
So, I've bitten the bullet and am converting some of my asp.net 1.1 sites to asp.net 2.0, now after many issues I have come to a stop with the objectdatasource and gridviews and maybe someone can...
4
by: Jonathan Wood | last post by:
Greetings, I have a GridView control. For a couple of reasons, I ended up with a TemplateField to contain my Edit and Delete links, something like this: <asp:TemplateField ShowHeader="False">...
0
by: Nick | last post by:
Hey there, I have a GridView on an ASP.NET / VB page and currently it has an attribute called DataKeyNames which has a reference to an XML attribute name, for example. <asp:GridView...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.