W
william.oram
I have a DataGrid and am attempting to have in-grid data editing. At
the moment I'm working with a single DropDownList:
public void roleList_Update(Object sender,
DataGridCommandEventArgs e)
{
int newRoleID = 666;
DropDownList ddl = (DropDownList)
e.Item.FindControl("ddlRoleEdit");
if (ddl != null)
newRoleID = int.Parse(ddl.SelectedValue);
roleListRowSQLAdapter.SelectCommand.Parameters["@currentRow"].Value =
(int) roleList.DataKeys[e.Item.ItemIndex];
roleListRowSQLAdapter.Fill(roleListRowDataSet);
roleListRowDataSet.ContactRoleDetailRow crd =
roleListRowDataSet.ContactRoleDetail[0]; /* BOOM! */
crd.Role = ddl.SelectedValue;
roleListRowSQLAdapter.Update(roleListRowDataSet.Co
ntactRoleDetail);
}
The commented line above is where the code breaks; the page complains
that 'There is no row at position 0.' Now, I understand this to mean
rowListRowDataSet is empty. But why? It was generated from an SQL
adapter and a SELECT statement I'm sure works. The parameter
@currentRow is valid, too. Isn't the 'Generate Dataset...' command all
that's needed to make a functioning DataSet? I'm picking this stuff up
by myself, so I may be missing some crucial idea.
Thanks!
the moment I'm working with a single DropDownList:
public void roleList_Update(Object sender,
DataGridCommandEventArgs e)
{
int newRoleID = 666;
DropDownList ddl = (DropDownList)
e.Item.FindControl("ddlRoleEdit");
if (ddl != null)
newRoleID = int.Parse(ddl.SelectedValue);
roleListRowSQLAdapter.SelectCommand.Parameters["@currentRow"].Value =
(int) roleList.DataKeys[e.Item.ItemIndex];
roleListRowSQLAdapter.Fill(roleListRowDataSet);
roleListRowDataSet.ContactRoleDetailRow crd =
roleListRowDataSet.ContactRoleDetail[0]; /* BOOM! */
crd.Role = ddl.SelectedValue;
roleListRowSQLAdapter.Update(roleListRowDataSet.Co
ntactRoleDetail);
}
The commented line above is where the code breaks; the page complains
that 'There is no row at position 0.' Now, I understand this to mean
rowListRowDataSet is empty. But why? It was generated from an SQL
adapter and a SELECT statement I'm sure works. The parameter
@currentRow is valid, too. Isn't the 'Generate Dataset...' command all
that's needed to make a functioning DataSet? I'm picking this stuff up
by myself, so I may be missing some crucial idea.
Thanks!