DataGrid1.DataKeys[e.Item.ItemIndex].ToString();为什么不能返回值。
如下语句
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
运行期返回错误,key值为null
e.Item.ItemIndex可以正确返回值。(相应数据行的索引号)。
哪位帮忙解答一下。。。
谢谢
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string productName;
decimal unitPrice;
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb;
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
productName = tb.Text;
tb = (TextBox)(e.Item.Cells[3].Controls[0]);
unitPrice = Convert.ToDecimal(tb.Text);
DataSet1.ProductsRow r;
r=dataSet11.Products.FindByProductID(int.Parse(key));
// Updates the dataset table.
r.ProductName=productName;
r.UnitPrice=unitPrice;
sqlDataAdapter1.Update(dataSet11);
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
运行期返回错误,key值为null
e.Item.ItemIndex可以正确返回值。(相应数据行的索引号)。
哪位帮忙解答一下。。。
谢谢
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string productName;
decimal unitPrice;
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb;
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
productName = tb.Text;
tb = (TextBox)(e.Item.Cells[3].Controls[0]);
unitPrice = Convert.ToDecimal(tb.Text);
DataSet1.ProductsRow r;
r=dataSet11.Products.FindByProductID(int.Parse(key));
// Updates the dataset table.
r.ProductName=productName;
r.UnitPrice=unitPrice;
sqlDataAdapter1.Update(dataSet11);
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
...全文
相关推荐
ASP.NET中DataGrid的使用指南
三、DataGridItem及其属性1. ItemIndex:获取行在Items集合中的索引。2. ItemType:返回行的类型,如Header、Item、AlternatingItem等。3.
ASP.NET程序中常用的三十三种代码
Employee where emp_id = " + intEmpID.ToString();```在上面的代码中,我们使用 DataGrid 控件的 DataKeys 属性来获取选定的记录,然后使用
ASPNET程序中常用的三十三种代码
例如,删除特定ID的记录: ```csharp int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex]; string deleteCmd =
ASP.NET中常用的三十三种代码第1/7页
```csharp int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex]; string deleteCmd = "Delete from
ASP.NET中DataGrid和DataList控件用法比较
#### 三、深入解析DataGridItem**1. DataGridItem的属性**- **ItemIndex**:返回该行在`Items`集合中的索引。


