/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void dgStaffFamilyMember_OnRowDataBound(object sender, DataGridViewRowEventArgs e) { if (e.Row.RowType == DataGridViewRowType.DataRow) { List<DSIStaffFamilyMember> dataSource = this.FamilyMemberDataSource; if (dataSource != null && dataSource.Count > 0) { DSIStaffFamilyMember data = dataSource[e.Row.RowIndex]; if (data != null) { //姓名。 TextBoxEx txtMemberName = e.Row.Cells[0].FindControl("txtMemberName") as TextBoxEx; if (txtMemberName != null) txtMemberName.Text = data.MemberName; //关系。 DropDownListEx ddlRelation = e.Row.Cells[1].FindControl("ddlRelation") as DropDownListEx; if (ddlRelation != null) { this.ListControlsDataSourceBind(ddlRelation, this.presenter.EnumDataSource(typeof(EnumRelation))); ddlRelation.SelectedValue = data.Relation.ToString(); } //性别。 DropDownListEx ddlGender = e.Row.Cells[2].FindControl("ddlGender") as DropDownListEx; if (ddlGender != null) { this.ListControlsDataSourceBind(ddlGender, this.presenter.EnumDataSource(typeof(EnumGender))); ddlGender.SelectedValue = data.Gender.ToString(); } //政治面貌。 DropDownListEx ddlPoliticalFace = e.Row.Cells[3].FindControl("ddlPoliticalFace") as DropDownListEx; if (ddlPoliticalFace != null) { this.ListControlsDataSourceBind(ddlPoliticalFace, this.presenter.EnumDataSource(typeof(EnumPoliticalFace))); ddlPoliticalFace.SelectedValue = data.PoliticalFace.ToString(); } //身份证号。 TextBoxEx txtIDCard = e.Row.Cells[4].FindControl("txtIDCard") as TextBoxEx; if (txtIDCard != null) txtIDCard.Text = data.IDCard; //出生日期。 TextBoxEx txtBirthday = e.Row.Cells[5].FindControl("txtBirthday") as TextBoxEx; if (txtBirthday != null && (data.Birthday != DateTime.MinValue && data.Birthday != DateTime.MaxValue)) { txtBirthday.Text = string.Format("{0:yyyy-MM}", data.Birthday); } //if (txtIDCard != null && txtBirthday != null) //{ // txtIDCard.Attributes["onchange"] = string.Format("javascript:IDCardToBirthday('{0}','{1}')", txtIDCard.ClientID, txtBirthday.ClientID); //} //健康状况。 DropDownListEx ddlHealthStatus = e.Row.Cells[6].FindControl("ddlHealthStatus") as DropDownListEx; if (ddlHealthStatus != null) { this.ListControlsDataSourceBind(ddlHealthStatus, this.presenter.EnumDataSource(typeof(EnumHealthStatus))); ddlHealthStatus.SelectedValue = data.HealthStatus.ToString(); } //月收入。 TextBoxEx txtIncome = e.Row.Cells[7].FindControl("txtIncome") as TextBoxEx; if (txtIncome != null) txtIncome.Text = string.Format("{0:N2}", data.Income); //身份。 DropDownListEx ddlMemberTheidentity = e.Row.Cells[8].FindControl("ddlMemberTheidentity") as DropDownListEx; if (ddlMemberTheidentity != null) { this.ListControlsDataSourceBind(ddlMemberTheidentity, this.presenter.EnumDataSource(typeof(EnumMemberTheidentity))); ddlMemberTheidentity.SelectedValue = data.Theidentity.ToString(); } //单位或学校。 TextBoxEx txtUnitSchool = e.Row.Cells[9].FindControl("txtUnitSchool") as TextBoxEx; if (txtUnitSchool != null) txtUnitSchool.Text = data.UnitSchool; } } } }
/// <summary> /// 触发<see cref="RowCreated"/>事件。 /// </summary> /// <param name="e"></param> protected virtual void OnRowCreated(DataGridViewRowEventArgs e) { DataGridViewRowEventHandler handler = this.RowCreated; if (handler != null) handler(this, e); }
/// <summary> /// 触发<see cref="RowDataBound"/>事件。 /// </summary> /// <param name="e"></param> protected virtual void OnRowDataBound(DataGridViewRowEventArgs e) { DataGridViewRowEventHandler handler = this.RowDataBound; if (handler != null) { if (e != null && (e.Row.RowType == DataGridViewRowType.Header)) { e.Row.Attributes["align"] = "center"; e.Row.Attributes["valign"] = "middle"; } handler(this, e); } }
DataGridViewRow CreateRow(int rowIndex, int dataSourceIndex, DataGridViewRowType rowType, DataGridViewRowState rowState, bool dataBind, object dataItem, DataControlFieldEx[] fields, TableRowCollection rows, PagedDataSourceEx pagedDataSource) { DataGridViewRow row = this.CreateRow(rowIndex, dataSourceIndex, rowType, rowState); DataGridViewRowEventArgs e = new DataGridViewRowEventArgs(row); if (rowType != DataGridViewRowType.Footer) this.InitializeRow(row, fields); else this.InitializePager(row, fields.Length, pagedDataSource); if (dataBind) row.DataItem = dataItem; this.OnRowCreated(e); rows.Add(row); if (dataBind) { row.DataBind(); this.OnRowDataBound(e); row.DataItem = null; } return row; }