GridView with BusinessObjects

R

Robert Warnestam

Hi,

When switching from using a DataGrid to a GridView a run into a problem.

I want to show a list of users which I receive from a business object.

void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Get a list of all users. (a dataset with fields; UserID, FirstName+++)
DataSet users = TapUser.GetAllUsers();
// Set the datasource and the primary key
GridView1.DataSource = users;
GridView1.DataKeyNames = new string[] {"UserID"};
GridView1.DataBind();
}
}
The problem is that I receive the following error message "Index was outside the bounds
of the array."

What am I doing wrong?

Thanks

Robert Warnestam
 
R

Robert Warnestam

Comment,

If I remove DataKeyNames I get up the grid. But I need the keys when using command buttons like select and edit.

One way to solve it could be to manually set up CommandArguments on some buttons, but wouldn't that be a wrong aproach?

/Robert
"Robert Warnestam" <[email protected]> skrev i meddelandet Hi,

When switching from using a DataGrid to a GridView a run into a problem.

I want to show a list of users which I receive from a business object.

void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Get a list of all users. (a dataset with fields; UserID, FirstName+++)
DataSet users = TapUser.GetAllUsers();
// Set the datasource and the primary key
GridView1.DataSource = users;
GridView1.DataKeyNames = new string[] {"UserID"};
GridView1.DataBind();
}
}
The problem is that I receive the following error message "Index was outside the bounds
of the array."

What am I doing wrong?

Thanks

Robert Warnestam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top