GridView的RowCreated与RowDataBound事件
2011-02-18 11:42
344 查看
RowDataBound是数据绑定的时候才会触发,RowCreated是每次呈现的时候都要触发,RowCreated先于RowDataBound执行。
举个列,如果页面回发后发生过GridView.databind(),那么两个事件都会触发。如果没发生GridView.databind(),那么就只会触发RowCreated。
事件执行顺序:
一、GridView 显示绑定的数据顺序如下:
DataBinding ->RowCreated ->RowDataBound ->...... ->DataBound
/// <summary>
/// 初始化gridview时绑定编辑里的下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvCustomerList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
string id = this.gdvCustomerList.DataKeys[e.Row.RowIndex].Value.ToString();
//取得所属行业列表
DataTable dtTrade = customerDetailBLL.GetTradeListByTypeName();
//自定义下拉列表
NewDropDownList ddl = new NewDropDownList(dtTrade);
ddl.ID = "ddlss";
ddl.DataTextField = "kindname";
ddl.DataValueField = "kindid";
ddl.DataSource = dtTrade;
ddl.DataBind();
ddl.SelectedValue = customerBLL.Trade(id).Rows[0][0].ToString();
e.Row.Cells[10].Controls.Add(ddl);
}
}
/// <summary>
/// 初始化gridview时绑定编辑里的下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvCustomerList_RowCreated(object sender, GridViewRowEventArgs e)
{
//if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
//和下句的效果是一样的,编辑时偶数行,奇数行都可以添加到
if ((e.Row.RowState & DataControlRowState.Edit) != 0)
{
string id = this.gdvCustomerList.DataKeys[e.Row.RowIndex].Value.ToString();
//取得所属行业列表
DataTable dtTrade = customerDetailBLL.GetTradeListByTypeName();
//自定义下拉列表
NewDropDownList ddl = new NewDropDownList(dtTrade);
ddl.ID = "ddlss";
ddl.DataTextField = "kindname";
ddl.DataValueField = "kindid";
ddl.DataSource = dtTrade;
ddl.DataBind();
ddl.SelectedValue = customerBLL.Trade(id).Rows[0][0].ToString();
e.Row.Cells[10].Controls.Add(ddl);
}
}
举个列,如果页面回发后发生过GridView.databind(),那么两个事件都会触发。如果没发生GridView.databind(),那么就只会触发RowCreated。
事件执行顺序:
一、GridView 显示绑定的数据顺序如下:
DataBinding ->RowCreated ->RowDataBound ->...... ->DataBound
/// <summary>
/// 初始化gridview时绑定编辑里的下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvCustomerList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
string id = this.gdvCustomerList.DataKeys[e.Row.RowIndex].Value.ToString();
//取得所属行业列表
DataTable dtTrade = customerDetailBLL.GetTradeListByTypeName();
//自定义下拉列表
NewDropDownList ddl = new NewDropDownList(dtTrade);
ddl.ID = "ddlss";
ddl.DataTextField = "kindname";
ddl.DataValueField = "kindid";
ddl.DataSource = dtTrade;
ddl.DataBind();
ddl.SelectedValue = customerBLL.Trade(id).Rows[0][0].ToString();
e.Row.Cells[10].Controls.Add(ddl);
}
}
/// <summary>
/// 初始化gridview时绑定编辑里的下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvCustomerList_RowCreated(object sender, GridViewRowEventArgs e)
{
//if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
//和下句的效果是一样的,编辑时偶数行,奇数行都可以添加到
if ((e.Row.RowState & DataControlRowState.Edit) != 0)
{
string id = this.gdvCustomerList.DataKeys[e.Row.RowIndex].Value.ToString();
//取得所属行业列表
DataTable dtTrade = customerDetailBLL.GetTradeListByTypeName();
//自定义下拉列表
NewDropDownList ddl = new NewDropDownList(dtTrade);
ddl.ID = "ddlss";
ddl.DataTextField = "kindname";
ddl.DataValueField = "kindid";
ddl.DataSource = dtTrade;
ddl.DataBind();
ddl.SelectedValue = customerBLL.Trade(id).Rows[0][0].ToString();
e.Row.Cells[10].Controls.Add(ddl);
}
}
相关文章推荐
- 关于Anthem中的GridView事件RowCreated和RowDatabound
- GridView的RowCreated与RowDataBound事件区别
- GridView的RowCreated与RowDataBound事件区别
- GridView的RowCreated与RowDataBound事件区别
- winform中datagridview事件RowPrePaint中类似与webform中的gridview的rowdatabound事件
- gridview-----添加OnRowDeleting事件及确认事件OnRowCreated
- GridView控件RowCreated事件的操作——鼠标动作
- GridView的RowDataBound事件可做的一些事情
- AspxGridView自定义列CustomColumnDisplayText事件与GridView中的rowdatabound事件一样
- GridView的RowDataBound和RowCommand事件中获取某行某列的值
- GridViewRow可以任意位置单击引发事件的方法
- GridViewRow可以任意位置单击引发事件的方法
- GridView控件RowDataBound事件中获取列字段的几种方法
- GridView.RowCommand 事件
- gridView RowDataBound事件详解
- GridView使用之RowCommand事件的使用
- 当使用EntityDataSource作为GridView的数据源时,在RowDataBound事件处理方法中得到对应当前行的实体对象
- GridView的RowDataBound事件 获取当前行的某个数据列
- Dev GridView RowCellClick事件与MouseDown事件
- GridView.RowDataBound 事件