我是新手,今天阅读了MSDN里面的一段代码,
// C#
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// Change the data in the dataset.
for (int i=1; i <= AuthorData.authors.Columns.Count; i++)
{
TextBox t = (TextBox)(e.Item.Cells[i].Controls[0]);
DataRow row = AuthorData.authors[e.Item.DataSetIndex];
row[AuthorData.authors.Columns[i-1].Caption] = t.Text;
}
// Update the database.
if (AuthorData.HasChanges())
{
AuthorsWebClient.localhost.AuthorsService ws =
new AuthorsWebClient.localhost.AuthorsService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
AuthorsWebClient.localhost.authors1 diffAuthors =
new AuthorsWebClient.localhost.authors1();
diffAuthors.Merge(AuthorData.GetChanges());
ws.UpdateAuthors(diffAuthors);
AuthorData.Merge(diffAuthors);
}
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}对这句DataRow row = AuthorData.authors[e.Item.DataSetIndex];不太理解。
AuthorData应该是dataset吧?authors是表名?那这个代表什么?MSDN上说它是索引,但我不知道他代表了什么东西?请了解得帮我解惑,谢谢。
// C#
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// Change the data in the dataset.
for (int i=1; i <= AuthorData.authors.Columns.Count; i++)
{
TextBox t = (TextBox)(e.Item.Cells[i].Controls[0]);
DataRow row = AuthorData.authors[e.Item.DataSetIndex];
row[AuthorData.authors.Columns[i-1].Caption] = t.Text;
}
// Update the database.
if (AuthorData.HasChanges())
{
AuthorsWebClient.localhost.AuthorsService ws =
new AuthorsWebClient.localhost.AuthorsService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
AuthorsWebClient.localhost.authors1 diffAuthors =
new AuthorsWebClient.localhost.authors1();
diffAuthors.Merge(AuthorData.GetChanges());
ws.UpdateAuthors(diffAuthors);
AuthorData.Merge(diffAuthors);
}
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}对这句DataRow row = AuthorData.authors[e.Item.DataSetIndex];不太理解。
AuthorData应该是dataset吧?authors是表名?那这个代表什么?MSDN上说它是索引,但我不知道他代表了什么东西?请了解得帮我解惑,谢谢。
authors是表的名字e.Item.DataSetIndex就是行号就是取AuthorData中表authors里的第e.Item.DataSetIndex行
private void dataGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.dataGrid.EditItemIndex = e.Item.ItemIndex;
this.dataGrid.DataBind();
}e.Item.ItemIndex又代表什么呢?