我想在DataGrid控件中添加下拉列表,
执行编辑按钮时执行下面的代码
if (e.Item.ItemType == ListItemType.EditItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
string current = drv["Label1"].ToString();
DropDownList ddl = (DropDownList)e.Item.FindControl("ddl");
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(current));
}
出现的错误是:
Label1 既不是表 Table 的 DataColumn 也不是 DataRelation
执行编辑按钮时执行下面的代码
if (e.Item.ItemType == ListItemType.EditItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
string current = drv["Label1"].ToString();
DropDownList ddl = (DropDownList)e.Item.FindControl("ddl");
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(current));
}
出现的错误是:
Label1 既不是表 Table 的 DataColumn 也不是 DataRelation
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control. In this example, the
// ItemDataBound event is used to format the items in the
// CurrencyColumn in currency format.
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
// Retrieve the text of the CurrencyColumn from the DataGridItem
// and convert the value to a Double.
Double Price = Convert.ToDouble(e.Item.Cells[2].Text); // Format the value as currency and redisplay it in the DataGrid.
e.Item.Cells[2].Text = Price.ToString("c");
}
}
在MSDN中找到的!
应该可以,你要对单元格操作就用Cell