devexpress中应用于girdviw中HtmlDataCellPrepared事件与CellEditorInitialize事件的区别

HtmlDataCellPrepared 事件为页面展示的时候对页面做的初始化(将id变为name)

​CellEditorInitialize 事件为页面在编辑时(新增、修改)时做的初始化,如将值填入下拉列表中。

///

/// 初始化GRID的部门名称

///

protected void grid_UserList_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)

{

DataTable dt = new DataTable();

dt = customerservicebll.DeptList(PEOID).Tables[0];//获取登录企业ID下的所有部门列表

if (e.DataColumn.FieldName == "DEPID")

{

DataRow[] Row = (DataRow[])dt.Select(" DEPID = " + e.CellValue.ToString() + " ");//根据每行部门ID筛选dt中对应的部门名称并放入数组

foreach (DataRow row in Row)

{

e.Cell.Text = row["DEPNAME"].ToString();//在数组中找到DEPNAME标记的值赋值给单元格

}

}

}

///

/// 编辑时各种初始化

///

protected void grid_UserList_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)

{

if (!grid_UserList.IsNewRowEditing)

{

if (e.Column.FieldName == "USERPWD")

{

ASPxTextBox textbox = new ASPxTextBox();

textbox = e.Editor as ASPxTextBox;

textbox.Enabled = false;

textbox.Password = true;

//e.Editor.Enabled = false;

}

}

else

{

if (e.Column.FieldName == "USERPWD")

{

e.Editor.Value = "888888";

}

}

if (e.Column.FieldName == "DEPID")

{

ASPxComboBox combox = new ASPxComboBox();

combox = e.Editor as ASPxComboBox;

DataTable dt = new DataTable();

dt = customerservicebll.DeptList(PEOID).Tables[0];

if (dt.Rows.Count > 0)

{

foreach (DataRow dr in dt.Rows)

{

combox.Items.Add(dr["DEPNAME"].ToString(), dr["DEPID"].ToString());

}

}

}

if (e.Column.FieldName == "TPOST_ID")

{

ASPxComboBox combox = new ASPxComboBox();

combox = e.Editor as ASPxComboBox;

DataTable dt = new DataTable();

dt = customerservicebll.PostList(PEOID).Tables[0];

if (dt.Rows.Count > 0)

{

foreach (DataRow dr in dt.Rows)

{

combox.Items.Add(dr["POSTNAME"].ToString(), dr["TPOST_ID"].ToString());

}

}

}

}

posted @ 2015-12-27 14:47  小鹿的无名书  阅读(1055)  评论(0编辑  收藏  举报