“组合式”Server控件中包含的DataGrid对象,无法响应一些事件
我要以创建“组合式”控件的方式,给DataGrid控件增加一些功能,我的控件的重载的CreateChildControls()方法中写了如下的代码(大致):
this.m_dataGrid1 = new DataGrid()
// “编辑”列
EditCommandColumn eccCol = new EditCommandColumn();
eccCol.HeaderText = "编辑";
eccCol.EditText = "[E]";
eccCol.UpdateText = "[U]";
eccCol.CancelText = "[C]";
m_dgrdShow.Columns.Add(eccCol);
// “删除”列
ButtonColumn btnCol = new ButtonColumn();
btnCol.HeaderText = "删除";
btnCol.CommandName = "delete";
btnCol.Text = "[D]";
m_dgrdShow.Columns.Add(btnCol);
// DataGrid 事件……
m_dgrdShow.ItemCommand += new DataGridCommandEventHandler(m_dgrdShow_ItemCommand);
m_dgrdShow.CancelCommand += new DataGridCommandEventHandler(m_dgrdShow_CancelCommand);
m_dgrdShow.EditCommand += new DataGridCommandEventHandler(m_dgrdShow_EditCommand);
m_dgrdShow.UpdateCommand += new DataGridCommandEventHandler(m_dgrdShow_UpdateCommand);
m_dgrdShow.ItemDataBound += new DataGridItemEventHandler(m_dgrdShow_ItemDataBound);
BuildDataGrid(); // 生成一些显示数据的BoundColumn列对象并添加到DataGrid的列集合中
BindDataGrid(); // 绑定数据
this.Controls.Add(this.m_dgrdShow);
现在,我可以正常的显示数据,并能够响应EditCommand事件,但是UpdateCommand和CancelCommand事件则无法响应(用断点测试得知)……
郁闷无比,请各位高人指点~
我觉得问题原因可能是页面事件引发顺序的问题,我的自定义控件少了一道什么工序……
this.m_dataGrid1 = new DataGrid()
// “编辑”列
EditCommandColumn eccCol = new EditCommandColumn();
eccCol.HeaderText = "编辑";
eccCol.EditText = "[E]";
eccCol.UpdateText = "[U]";
eccCol.CancelText = "[C]";
m_dgrdShow.Columns.Add(eccCol);
// “删除”列
ButtonColumn btnCol = new ButtonColumn();
btnCol.HeaderText = "删除";
btnCol.CommandName = "delete";
btnCol.Text = "[D]";
m_dgrdShow.Columns.Add(btnCol);
// DataGrid 事件……
m_dgrdShow.ItemCommand += new DataGridCommandEventHandler(m_dgrdShow_ItemCommand);
m_dgrdShow.CancelCommand += new DataGridCommandEventHandler(m_dgrdShow_CancelCommand);
m_dgrdShow.EditCommand += new DataGridCommandEventHandler(m_dgrdShow_EditCommand);
m_dgrdShow.UpdateCommand += new DataGridCommandEventHandler(m_dgrdShow_UpdateCommand);
m_dgrdShow.ItemDataBound += new DataGridItemEventHandler(m_dgrdShow_ItemDataBound);
BuildDataGrid(); // 生成一些显示数据的BoundColumn列对象并添加到DataGrid的列集合中
BindDataGrid(); // 绑定数据
this.Controls.Add(this.m_dgrdShow);
现在,我可以正常的显示数据,并能够响应EditCommand事件,但是UpdateCommand和CancelCommand事件则无法响应(用断点测试得知)……
郁闷无比,请各位高人指点~
我觉得问题原因可能是页面事件引发顺序的问题,我的自定义控件少了一道什么工序……
...全文
相关推荐
Microsoft DataGrid控件
数据源可以是SQL Server、Access数据库,也可以是ADO.NET对象如DataSet或DataTable。DataGrid控件会自动根据数据源的结构生成列,并显示数据。
VB中DataGrid_控件的使用秘集
**数据绑定**:将DataGrid控件与数据源绑定是其基本功能。你可以使用`SetDataSource`方法将数据集(DataSet)或其他数据源对象绑定到DataGrid。
将MS DataGrid控件与ADO一起使用
**处理事件** 为DataGrid的事件(如点击、编辑、排序)编写事件处理函数,以响应用户的交互。
VC使用ADO Data和DataGrid控件实现遍历、修改、删除、添加.rar
同时,可以监听控件的事件,比如CellClick或CellChange,实现对用户操作的响应。
ActiveX控件中的DataGrid或ADO Data控件在VS版本中的使用
**进一步的定制**开发者还可以对DataGrid控件进行更多的自定义,如改变列宽、设置列头文本、添加列样式等。同时,可以通过编程方式响应用户操作,比如在用户编辑数据后更新数据库。


