日期:2014-05-17 浏览次数:20513 次
DataTable myda = new DataTable()
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataColumn datacol = myda.Columns.Add("UnitName");
datacol.DataType = Type.GetType("System.String");
datacol = myda.Columns.Add("ProjCharger");
datacol.DataType = Type.GetType("System.String");
ViewState["table"] = myda;
grid.DataSource = myda;
grid.DataBind();
this.grid.KeyFieldName = "UnitName";
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
grid.AddNewRow();
}
protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) //插入事件
{
myda = (DataTable)ViewState["table"];
DataRow darow = myda.NewRow();
darow[0] = e.NewValues[0].ToString();
darow[1] = e.NewValues[1].ToString();
myda.Rows.Add(darow);
grid.DataSource = myda;
grid.DataBind();
ViewState["table"] = myda;
grid.CancelEdit();
e.Cancel = true;
}