protected override void CreateChildControls() { if (Convert.ToBoolean(ViewState["IsFirst"])) { //Insert Move Up Column TemplateField tempMoveUp = new TemplateField(); tempMoveUp.HeaderText = WebControlLocalization.GetText("ManageGridView_MoveUp"); tempMoveUp.HeaderStyle.Width = new Unit("50"); Columns.Add(tempMoveUp); //Insert Move Down Column TemplateField tempMoveDown = new TemplateField(); tempMoveDown.HeaderText = WebControlLocalization.GetText("ManageGridView_MoveDown"); tempMoveDown.HeaderStyle.Width = new Unit("50"); Columns.Add(tempMoveDown); //Insert Operation Column TemplateField tempOperation = new TemplateField(); tempOperation.HeaderText = WebControlLocalization.GetText("ManageGridView_Operation"); tempOperation.HeaderStyle.Width = new Unit("100"); Columns.Add(tempOperation); ViewState["IsFirst"] = false; } base.CreateChildControls(); }
/// <summary> /// Generates the HTML markup to describe the current page (0-based) /// </summary> /// <param name="cell">TableCell</param> private void BuildCurrentPage(TableCell cell) { // Use a standard template: Page X of Y if (PageIndex < 0 || PageIndex >= PageCount) { cell.Text = EmptyDataText; } else { cell.Text = String.Format(WebControlLocalization.GetText("ManageGridView_CurrentPage"), (PageIndex + 1), PageCount, RecordCount, PageSize); } }
protected override void RenderAttributes(HtmlTextWriter writer) { this.Attributes.Add("type", "reset"); this.Attributes.Add("value", WebControlLocalization.GetText("ResetButton_Reset")); this.Attributes.Add("class", "btn_mouseout"); this.Attributes.Add("onmouseover", "this.className='btn_mouseover'"); this.Attributes.Add("onmouseout", "this.className='btn_mouseout'"); this.Attributes.Add("onmousedown", "this.className='btn_mousedown'"); this.Attributes.Add("onmouseup", "this.className='btn_mouseup'"); if (this.ApplyOnClickEvent) { this.Attributes.Add("onclick", "this.blur();"); } base.RenderAttributes(writer); }
/// <summary> /// 重写属性输出函数 /// </summary> /// <param name="writer">要写出到的 HTML 编写器</param> protected override void AddAttributesToRender(HtmlTextWriter writer) { this.Attributes.Add("class", "btn_mouseout"); this.Attributes.Add("onmouseover", "this.className='btn_mouseover'"); this.Attributes.Add("onmouseout", "this.className='btn_mouseout'"); this.Attributes.Add("onmousedown", "this.className='btn_mousedown'"); this.Attributes.Add("onmouseup", "this.className='btn_mouseup'"); switch (this.ButtonType) { case EnumButtonType.Add: this.Text = WebControlLocalization.GetText("Button_Add"); if (this.ApplyOnClickEvent) { this.Attributes.Add("onclick", "this.blur();"); } break; case EnumButtonType.Save: this.Text = WebControlLocalization.GetText("Button_Save"); if (this.ApplyOnClickEvent) { this.Attributes.Add("onclick", "this.blur();"); } break; case EnumButtonType.Delete: this.Text = WebControlLocalization.GetText("Button_Delete"); if (this.ApplyOnClickEvent) { this.Attributes.Add("onclick", "this.blur();if (zrWebCheckBox_CheckHasData('chkGroup1')) {return confirm('您确定要删除所选内容吗?');}else {alert('您还未选择任何记录!');return false;}"); } break; case EnumButtonType.ResetPassword: this.Text = WebControlLocalization.GetText("Button_ResetPassword"); if (this.ApplyOnClickEvent) { this.Attributes.Add("onclick", "this.blur();return confirm('" + WebControlLocalization.GetText("Button_ResetConfirmation") + "');"); } break; } base.AddAttributesToRender(writer); }
/// <summary> /// Generates the HTML markup for the Next/Prev navigation bar /// </summary> /// <param name="cell"></param> private void BuildNextPrevUI(TableCell cell) { bool isValidPage = (PageIndex >= 0 && PageIndex <= PageCount - 1); bool canMoveBack = (PageIndex > 0); bool canMoveForward = (PageIndex < PageCount - 1); // Render the << button LinkButton first = new LinkButton(); first.ID = "First"; first.CommandName = "Page"; first.CommandArgument = "First"; first.Text = WebControlLocalization.GetText("ManageGridView_FirstPage"); first.Enabled = isValidPage && canMoveBack; first.CssClass = "list_link"; cell.Controls.Add(first); // Add a separator cell.Controls.Add(new LiteralControl(" ")); // Render the < button LinkButton prev = new LinkButton(); prev.ID = "Prev"; prev.CommandName = "Page"; prev.CommandArgument = "Prev"; prev.Text = WebControlLocalization.GetText("ManageGridView_PreviousPage"); prev.Enabled = isValidPage && canMoveBack; prev.CssClass = "list_link"; cell.Controls.Add(prev); // Add a separator cell.Controls.Add(new LiteralControl(" ")); // Render the > button LinkButton next = new LinkButton(); next.ID = "Next"; next.CommandName = "Page"; next.CommandArgument = "Next"; next.Text = WebControlLocalization.GetText("ManageGridView_NextPage"); next.Enabled = isValidPage && canMoveForward; next.CssClass = "list_link"; cell.Controls.Add(next); // Add a separator cell.Controls.Add(new LiteralControl(" ")); // Render the >> button LinkButton last = new LinkButton(); last.ID = "Last"; last.CommandName = "Page"; last.CommandArgument = "Last"; last.Text = WebControlLocalization.GetText("ManageGridView_LastPage"); last.Enabled = isValidPage && canMoveForward; last.CssClass = "list_link"; cell.Controls.Add(last); // Add a separator cell.Controls.Add(new LiteralControl(" ")); //Render a textbox pagenum.ID = "pagenum"; pagenum.Width = new Unit("20"); pagenum.Height = new Unit("13"); pagenum.Text = Convert.ToString(PageIndex + 1); pagenum.CssClass = "gridview_pagenum"; cell.Controls.Add(pagenum); // Render navigation link LinkButton pageNavigator = new LinkButton(); pageNavigator.ID = "pageNavigator"; pageNavigator.Click += new EventHandler(pageNavigator_Click); pageNavigator.Text = WebControlLocalization.GetText("ManageGridView_GoPage"); pageNavigator.CssClass = "list_link"; cell.Controls.Add(pageNavigator); }
protected override void OnRowCreated(GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { //DisplaySortOrderImages(SortExpressionCust, e.Row); //this.CreateRow(0, 0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); } if (this.AllowPaging) { IEnumerable dataSource = this.DataSource as IEnumerable; if (dataSource != null) { IEnumerator iEnum = dataSource.GetEnumerator(); int i = 0; while (iEnum.MoveNext()) { i++; } this.Page.Visible = (i > 0); } } //固定表头 ziyan 2006-12-16 //if (e.Row.RowType == DataControlRowType.Header) //{ // foreach (TableCell cell in e.Row.Cells) // { // cell.CssClass = "fhc"; // } //} if (e.Row.RowType == DataControlRowType.DataRow) { //insert ImageButton for move up ImageButton imgbtnup = new ImageButton(); imgbtnup.ID = "ImageButtonUp"; imgbtnup.ImageUrl = "../images/gridview/up.gif"; imgbtnup.ToolTip = WebControlLocalization.GetText("ManageGridView_MoveUp"); imgbtnup.CommandName = "MoveUp"; imgbtnup.CommandArgument = (this.Rows.Count).ToString(); e.Row.Cells[this.Columns.Count - 3].Controls.Add(imgbtnup); //insert ImageButton for move up ImageButton imgbtndown = new ImageButton(); imgbtndown.ID = "ImageButtonDown"; imgbtndown.ImageUrl = "../images/gridview/down.gif"; imgbtndown.ToolTip = WebControlLocalization.GetText("ManageGridView_Down"); imgbtndown.CommandName = "MoveDown"; imgbtndown.CommandArgument = (this.Rows.Count).ToString(); e.Row.Cells[this.Columns.Count - 2].Controls.Add(imgbtndown); //insert ImageButton for edit HyperLink link = new HyperLink(); link.ID = "hyperLinkEdit"; link.ImageUrl = "../images/gridview/edit.gif"; link.ToolTip = WebControlLocalization.GetText("ManageGridView_Modify"); e.Row.Cells[this.Columns.Count - 1].Controls.Add(link); System.Web.UI.WebControls.Literal space = new System.Web.UI.WebControls.Literal(); space.Text = " "; e.Row.Cells[this.Columns.Count - 1].Controls.Add(space); //insert ImageButton for delete ImageButton imgbtndelete = new ImageButton(); imgbtndelete.ID = "ImageButtonDelete"; imgbtndelete.ImageUrl = "../images/gridview/delete.gif"; imgbtndelete.ToolTip = WebControlLocalization.GetText("ManageGridView_Delete"); imgbtndelete.CommandName = "Delete"; imgbtndelete.CommandArgument = (this.Rows.Count).ToString(); e.Row.Cells[this.Columns.Count - 1].Controls.Add(imgbtndelete); } else if (e.Row.RowType == DataControlRowType.Pager && this.AllowPaging) { TableCell tc = new TableCell(); e.Row.Controls.Clear(); Table t = new Table(); t.Width = Unit.Percentage(100); t.CellPadding = 0; t.CellSpacing = 0; // Build the table row TableRow row = new TableRow(); t.Rows.Add(row); // Build the cell with the page index TableCell cellPageDesc = new TableCell(); cellPageDesc.Style.Add("border", "0"); cellPageDesc.Style.Add("text-align", "left"); BuildCurrentPage(cellPageDesc); row.Cells.Add(cellPageDesc); // Build the cell with navigation bar TableCell cellNavBar = new TableCell(); if (PagingStyle == PagingStyle.PrevNext) { BuildNextPrevUI(cellNavBar); } else { BuildNumericPagesUI(cellNavBar); } cellNavBar.Style.Add("border", "0"); cellNavBar.Style.Add("text-align", "right"); row.Cells.Add(cellNavBar); tc.ColumnSpan = this.Columns.Count; tc.Controls.Add(t); // Add the table to the control tree e.Row.Controls.Add(tc); } base.OnRowCreated(e); }
protected override void OnRowDataBound(GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //Alternating BackColor when mouse moving if (base.Rows.Count % 2 == 0) { e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + GetColorName(this.RowStyle.BackColor) + "';"); } else { e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='" + GetColorName(this.AlternatingRowStyle.BackColor) + "';"); } //Highlight Color e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='" + GetColorName(this.SelectedRowStyle.BackColor) + "';"); //Confirm delete if (e.Row.Cells[this.Columns.Count - 1].Controls.Count > 0) { //do nothing if in design mode, otherwise vs cannot render the control. The code below only excute in running time. //Site != null && !Site.DesignMode || if (!this.DesignMode) { Label lblId = (Label)e.Row.FindControl("lblId"); if (lblId != null) { HyperLink btnEdit = (HyperLink)e.Row.Cells[this.Columns.Count - 1].FindControl("hyperLinkEdit"); if (btnEdit != null) { btnEdit.NavigateUrl = GetNavigationPageName() + "?action=modify&id=" + lblId.Text; } ImageButton btnDelete = (ImageButton)e.Row.Cells[this.Columns.Count - 1].FindControl("ImageButtonDelete"); if (btnDelete != null) { btnDelete.Attributes.Add("onclick", "javascript:return confirm('" + String.Format(WebControlLocalization.GetText("ManageGridView_DeleteConfirmation"), lblId.Text) + "');"); } } } } } base.OnRowDataBound(e); }