GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析(转)
2012-08-27 13:38
134 查看
严格的说,DataBinding,DataBound并不是GridView特有的事件,其他的控件诸如ListBox等也有DataBinding,DataBound事件。
DataBinding事件
MSDN解释:Occurs when the server control binds to a data source.
This event notifies the server control to perform any data-binding logic that has been written for it.
译为:该事件当服务器控件绑定数据时发生。
DataBound事件
MSDN解释:Occurs after the server control binds to a data source.
This event notifies the server control that any data binding logic written for it has completed.
译为:该事件当服务器控件完成数据绑定后发生。
RowCreated事件
MSDN解释:Occurs when a row is created in a GridView control.
译为:当GridView的行被创建时发生。
RowDataBound事件
MSDN解释:Occurs when a data row is bound to data in a GridView control.
译为:当GridView的行被绑定数据时发生。
四个事件的执行顺序:
假定GridView有3行数据
aspx代码
[xhtml]
view plaincopy
<asp:GridView
ID="GridViewMain"
runat="server"
AutoGenerateColumns="False"
OnDataBinding="GridViewMain_DataBinding"
OnDataBound="GridViewMain_DataBound"
OnRowCreated="GridViewMain_RowCreated"
OnRowDataBound="GridViewMain_RowDataBound"
>
cs代码(只含事件头)
[c-sharp]
view plaincopy
protected void GridViewMain_DataBinding(object sender,EventArgs e)
{
}
protected void GridViewMain_DataBound
(object sender,EventArgs e)
{
}
protected void GridViewMain_RowCreated(object sender, GridViewRowEventArgs e)
{
}
protected void GridViewMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
发生次序是:
1. DataBinding
2. RowCreated
3. RowDataBound
4. RowCreated
5. RowDataBound
6. RowCreated
7. RowDataBound
8. DataBound
GridView取得数据有3条,因此Row的相关事件执行3次。
另外,从字面本身也可知事件之间的区别
比如,DataBound,DataBinding两个事件,单词Bound是Bind的过去式,即DataBound是绑定事件完成后发生的。
还有诸如RowDeleted,RowDeleting,都可以从词义本身的差别加以区分。
DataBinding事件
MSDN解释:Occurs when the server control binds to a data source.
This event notifies the server control to perform any data-binding logic that has been written for it.
译为:该事件当服务器控件绑定数据时发生。
DataBound事件
MSDN解释:Occurs after the server control binds to a data source.
This event notifies the server control that any data binding logic written for it has completed.
译为:该事件当服务器控件完成数据绑定后发生。
RowCreated事件
MSDN解释:Occurs when a row is created in a GridView control.
译为:当GridView的行被创建时发生。
RowDataBound事件
MSDN解释:Occurs when a data row is bound to data in a GridView control.
译为:当GridView的行被绑定数据时发生。
四个事件的执行顺序:
假定GridView有3行数据
aspx代码
[xhtml]
view plaincopy
<asp:GridView
ID="GridViewMain"
runat="server"
AutoGenerateColumns="False"
OnDataBinding="GridViewMain_DataBinding"
OnDataBound="GridViewMain_DataBound"
OnRowCreated="GridViewMain_RowCreated"
OnRowDataBound="GridViewMain_RowDataBound"
>
cs代码(只含事件头)
[c-sharp]
view plaincopy
protected void GridViewMain_DataBinding(object sender,EventArgs e)
{
}
protected void GridViewMain_DataBound
(object sender,EventArgs e)
{
}
protected void GridViewMain_RowCreated(object sender, GridViewRowEventArgs e)
{
}
protected void GridViewMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
发生次序是:
1. DataBinding
2. RowCreated
3. RowDataBound
4. RowCreated
5. RowDataBound
6. RowCreated
7. RowDataBound
8. DataBound
GridView取得数据有3条,因此Row的相关事件执行3次。
另外,从字面本身也可知事件之间的区别
比如,DataBound,DataBinding两个事件,单词Bound是Bind的过去式,即DataBound是绑定事件完成后发生的。
还有诸如RowDeleted,RowDeleting,都可以从词义本身的差别加以区分。
相关文章推荐
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
- GridView 删除按钮事件执行顺序
- GridView事件说明及执行顺序
- 【分析】浅谈C#中Control的Invoke与BeginInvoke在主副线程中的执行顺序和区别(SamWang)
- GridView的RowCreated与RowDataBound事件区别
- GridView的RowCreated与RowDataBound事件区别
- GridView的 PreRender事件与 RowCreated、RowDataBound事件大乱斗
- GridView 删除事件的执行顺序
- 【分析】浅谈C#中Control的Invoke与BeginInvoke在主副线程中的执行顺序和区别(SamWang)
- GridView 删除按钮事件执行顺序
- GridView的RowDataBound事件和DataBound事件
- GridView的RowCreated与RowDataBound事件区别
- 【分析】浅谈C#中Control的Invoke与BeginInvoke在主副线程中的执行顺序和区别(SamWang)
- ASp.NET 2.0中Page事件的执行顺序
- ASP.NET 页面生命中的关键事件的执行顺序
- 关闭页面时window.location事件未执行的原因分析及解决方案
- Jquery 中两个页面载入后执行的函数的分析区别