private void BindGrid() { using (var appdb = new AppContext()) { int SupplierId = GetQueryIntValue("pid"); IQueryable <RLItems> q = appdb.allitems.Where(u => u.SupplierId == SupplierId); // 在职务名称中搜索 string searchText = ttbSearchMessage.Text.Trim(); if (!String.IsNullOrEmpty(searchText)) { q = q.Where(t => t.ItemName.Contains(searchText) || t.Sclass.Contains(searchText) || t.Material.Contains(searchText) || t.ItemNo.Contains(searchText)); } // 在查询添加之后,排序和分页之前获取总记录数 Grid1.RecordCount = q.Count(); // 排列和分页 q = SortAndPage <RLItems>(q, Grid1); Grid1.DataSource = q; Grid1.DataBind(); } if (!CheckPower("FinanceView")) { GridColumn column = Grid1.FindColumn("Price"); column.EnableColumnHide = true; } }
/// <summary> /// 列表按键绑定——修改列表控件属性 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { // PROD_KINDBll.GetInstence().BandDropDownListShowKind(this, (System.Web.UI.WebControls.DropDownList)Grid1.Rows[e.RowIndex].FindControl("KIND_NAME")); //System.Web.UI.WebControls.DropDownList Kind_n = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[e.RowIndex].FindControl("KIND_NAME"); int o = e.RowIndex; //GridRow gr = Grid1.Rows[e.RowIndex]; // + 1 DataRowView row = e.DataItem as DataRowView; if ((row).Row.Table.Rows[e.RowIndex][PROD_DEPTable.ENABLE].ToString() == "0") { var lbf = Grid1.FindColumn("ENABLE") as LinkButtonField; lbf.Icon = Icon.BulletCross; lbf.CommandArgument = "1"; } else { var lbf = Grid1.FindColumn("ENABLE") as LinkButtonField; lbf.Icon = Icon.BulletTick; lbf.CommandArgument = "0"; } //绑定是否编辑列 var lbfEdit = Grid1.FindColumn("ButtonEdit") as LinkButtonField; lbfEdit.Text = "编辑"; lbfEdit.Enabled = MenuInfoBll.GetInstence().CheckControlPower(this, "ButtonEdit"); }
protected void Button1_Click(object sender, EventArgs e) { CheckBoxField field2 = (CheckBoxField)Grid1.FindColumn("CheckBoxField2"); StringBuilder sb = new StringBuilder(); int selectedCount = Grid1.SelectedRowIndexArray.Length; if (selectedCount > 0) { sb.AppendFormat("共选中了 {0} 行:", selectedCount); sb.Append("<ol class=\"result\">"); for (int i = 0; i < selectedCount; i++) { int rowIndex = Grid1.SelectedRowIndexArray[i]; sb.Append("<li><ul>"); sb.AppendFormat("<li>行号:{0}</li>", rowIndex + 1); sb.AppendFormat("<li>是否在校(自动会发):{0}</li>", field2.GetCheckedState(rowIndex)); sb.Append("</ul></li>"); } sb.Append("</ol>"); } else { sb.Append("<strong>没有选中任何一行!</strong>"); } labResult.Text = sb.ToString(); }
protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e) { //// 如果绑定到 DataTable,那么这里的 DataItem 就是 DataRowView DataRowView row = e.DataItem as DataRowView; if (row == null) { return; } DateTime dt = new DateTime(1900, 1, 1); string shsj = row["Shsj"].ToString(); bool canAudit = !string.IsNullOrEmpty(shsj) && DateTime.TryParse(shsj, out dt) && dt <= DateTime.Now && DateTime.Now <= dt.AddDays(7); if (this.ddlZt.SelectedValue != "0" && !canAudit) { return; } WindowField lbfOper = Grid1.FindColumn("lbfOper") as WindowField; if (row["Lxrbh"].ToString() == TStar.Web.Globals.Account.Pkid) { lbfOper.Icon = FineUI.Icon.Pencil; lbfOper.ToolTip = "审核"; } }
// 行预绑定事件(显示图标列) protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e) { var log = e.DataItem as Log; var fld = Grid1.FindColumn("Icon") as FineUI.ImageField; fld.DataImageUrlFormatString = GetIconUrl(log.Lvl); }
protected void Grid1_PreDataBound(object sender, EventArgs e) { // 设置LinkButtonField的点击客户端事件 LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField; deleteField.OnClientClick = GetDeleteScript(Grid1); }
//行事件 protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e) { if (e.CommandName == "Delete") { int id = Convert.ToInt32(Grid1.Rows[e.RowIndex].Values[0]); int flag = operate.DeletePublishByID(id); if (flag >= 1) { Alert.ShowInParent("删除成功"); BindData(); } else { Alert.ShowInParent("删除失败"); } } else if (e.CommandName == "CheckBox1") { int id = Convert.ToInt32(Grid1.Rows[e.RowIndex].Values[0]); FineUI.CheckBoxField checkField = (FineUI.CheckBoxField)Grid1.FindColumn(e.ColumnIndex); bool checkState = checkField.GetCheckedState(e.RowIndex); int a = operate.UpdatePublishByID(id, checkState); if (a > 0) { Alert.ShowInParent("操作成功"); BindData(); } else { Alert.ShowInParent("操作失败"); } } }
protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e) { WindowField lbfModify = Grid1.FindColumn("lbfModify") as WindowField; LinkButtonField lbfDelete = Grid1.FindColumn("lbfDelete") as LinkButtonField; //// 如果绑定到 DataTable,那么这里的 DataItem 就是 DataRowView DataRowView row = e.DataItem as DataRowView; if (row != null) { switch (TStar.Utility.Common.ConvertHelper.EnumParse <TStar.Web.Globals.SystemSetting.Status>(row["Ztdm"].ToString())) { case TG.SystemSetting.Status.Draft: lbfModify.Icon = FineUI.Icon.Pencil; lbfDelete.Icon = FineUI.Icon.BulletCross; break; default: lbfModify.Icon = lbfDelete.Icon = FineUI.Icon.None; break; } switch (lbfDelete.Icon) { case FineUI.Icon.Decline: lbfDelete.CommandName = "Delete"; lbfDelete.ToolTip = "删除"; lbfDelete.ConfirmText = "确认删除?"; break; } } }
/// <summary> /// 列表按键绑定——修改列表控件属性 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { //绑定是否编辑列 var lbfGetOut = Grid1.FindColumn("ButtonGetOut") as LinkButtonField; lbfGetOut.Enabled = MenuInfoBll.GetInstence().CheckControlPower(this, "ButtonGetOut"); }
protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e) { if (e.CommandName == "UDISABLED") { //上架操作权限 if (!VerifyPurview(",SU-EDIT,")) { Alert.ShowInParent(CHECK_POWER_FAIL_ACTION_MESSAGE); return; } CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex); bool checkState = checkField.GetCheckedState(e.RowIndex); int result = new UserBLL().SetDisabled(Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]), checkState); string tipText = checkState ? "禁用" : "启用"; if (result > 0) { Alert.ShowInParent(tipText + "成功!"); BindData(); } else { Alert.ShowInParent(tipText + "失败!"); } } }
/// <summary> /// Grid1行点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string rowID = Grid1.DataKeys[e.RowIndex][0].ToString(); //string parentId = Grid1.DataKeys[e.RowIndex][1].ToString(); if (e.CommandName == "IsSelected") { CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn("ckbIsSelected"); if (checkField.GetCheckedState(e.RowIndex)) { if (!list.Contains(rowID)) { list.Add(rowID); } //if (!parentIds.Contains(parentId + "," + rowID)) //{ // parentIds.Add(parentId + "," + rowID); //} } else { if (list.Contains(rowID)) { list.Remove(rowID); } //if (parentIds.Contains(parentId + "," + rowID)) //{ // parentIds.Remove(parentId + "," + rowID); //} } } }
protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e) { if (e.CommandName == "UDISABLED") { //编辑权限 if (!VerifyPurview(",SM-SET,")) { Alert.ShowInParent(CHECK_POWER_FAIL_ACTION_MESSAGE); return; } CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex); bool checkState = checkField.GetCheckedState(e.RowIndex); int result = new PCBLL().SetDisabled(Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]), checkState); string tipText = (checkState ? "禁用" : "启用"); if (result > 0) { Alert.ShowInParent(tipText + "成功!"); BindData(); } else { Alert.ShowInParent(tipText + "失败!"); } } if (e.CommandName == "Edit") { txtID.Text = Grid1.DataKeys[e.RowIndex][0].ToString(); txtName.Text = HttpUtility.HtmlDecode(Grid1.DataKeys[e.RowIndex][1].ToString()); txtCode.Text = HttpUtility.HtmlDecode(Grid1.DataKeys[e.RowIndex][2].ToString()).Split('-')[1]; chkDisabled.Checked = Convert.ToBoolean(Grid1.DataKeys[e.RowIndex][3].ToString()); } }
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { Infobasis.Data.DataEntity.Client client = e.DataItem as Infobasis.Data.DataEntity.Client; DateTime?lastTraceDate = Convert.ToDateTime(client.LastTraceDate); FineUIPro.BoundField bfTraceNum = Grid1.FindColumn("bfTraceNum") as FineUIPro.BoundField; int columnIndexTraceNum = bfTraceNum.ColumnIndex; int lastTraceDays = Infobasis.Web.Util.DateHelper.GetClientTraceDays(lastTraceDate, DateTime.Now); e.Values[columnIndexTraceNum] = String.Format("<span class=\"{0}\" data-qtip=\"{4}\">{1}-{2}-{3}</span>", lastTraceDays >= 10 || lastTraceDays == 0 ? "traceWarning" : "traceNormal", Change.ToInt(lastTraceDays), 0, 0, string.Format("最后跟进已过:{0} 天", lastTraceDays)); FineUIPro.WindowField wfdisableClientField = Grid1.FindColumn("disableClientField") as FineUIPro.WindowField; if (client.Disabled.HasValue && client.Disabled.Value) { int columnIndexDisabled = wfdisableClientField.ColumnIndex; e.Values[columnIndexDisabled] = "<a class=\"ui-state-disabled\" disabled=\"disabled\" data-qtip=\"废单\">已废单</a>"; FineUIPro.WindowField changeToNextField = Grid1.FindColumn("changeToNextField") as FineUIPro.WindowField; int columnIndexToNext = changeToNextField.ColumnIndex; e.Values[columnIndexToNext] = ""; } }
/// <summary> /// 列表按键绑定——修改列表控件属性 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { int o = e.RowIndex; //GridRow gr = Grid1.Rows[e.RowIndex]; // + 1 DataRowView row = e.DataItem as DataRowView; if ((row).Row.Table.Rows[e.RowIndex][SHOP_PRICE_AREATable.ENABLE].ToString() == "0") { var lbf = Grid1.FindColumn("ENABLE") as LinkButtonField; lbf.Icon = Icon.BulletCross; lbf.CommandArgument = "1"; } else { var lbf = Grid1.FindColumn("ENABLE") as LinkButtonField; lbf.Icon = Icon.BulletTick; lbf.CommandArgument = "0"; } //绑定是否编辑列 var lbfEdit = Grid1.FindColumn("ButtonEdit") as LinkButtonField; lbfEdit.Text = "编辑"; lbfEdit.Enabled = MenuInfoBll.GetInstence().CheckControlPower(this, "ButtonEdit"); }
/// <summary> /// 这个事件会在渲染每一行前调用,因此改变了列的属性,那么渲染每一行时此列的属性都发生了变化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_PreRowDataBound(object sender, ExtAspNet.GridPreRowEventArgs e) { LinkButtonField lbfAction1 = Grid1.FindColumn("lbfAction1") as LinkButtonField; LinkButtonField lbfAction2 = Grid1.FindColumn("lbfAction2") as LinkButtonField; CheckBoxField cbxAtSchool = Grid1.FindColumn("cbxAtSchool") as CheckBoxField; if (e.RowIndex < 5) { cbxAtSchool.Enabled = true; lbfAction1.Enabled = true; lbfAction2.Enabled = true; } else { cbxAtSchool.Enabled = false; lbfAction1.Enabled = false; lbfAction2.Enabled = false; } // 如果绑定到 DataTable,那么这里的 DataItem 就是 DataRowView HyperLinkField linkField = Grid1.Columns[4] as HyperLinkField; DataRowView row = e.DataItem as DataRowView; if (row != null) { linkField.DataTextFormatString = "{0} (" + row["EntranceYear"].ToString() + ")"; } }
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { DataRowView row = e.DataItem as DataRowView; // 入学年份 string yen = row["完成情况"].ToString(); BoundField cyen = Grid1.FindColumn("完成情况") as BoundField; if (yen == "正在进行") { e.CellAttributes[cyen.ColumnIndex]["data-color"] = "color3"; } else if (yen == "完成") { e.CellAttributes[cyen.ColumnIndex]["data-color"] = "color2"; } // 性别 //int gender = Convert.ToInt32(row["Gender"]); //TemplateField cGender = Grid1.FindColumn("cGender") as TemplateField; //if (gender == 1) //{ // e.CellAttributes[cGender.ColumnIndex]["data-color"] = "color1"; //} }
//-------------------------------------------------- // Grid //-------------------------------------------------- // 行绑定事件(BUG: 若是admin则删除按钮无效,代码都对,但整列都变无效了) protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { User user = e.DataItem as User; // 设置职务列 var titleField = Grid1.FindColumn("Titles") as FineUI.BoundField; if (titleField != null) { string titles = ""; foreach (var item in user.Titles) { titles += item.Name + ","; } titles = titles.TrimEnd(','); titleField.DataFormatString = " " + titles; } // 设置角色列 var roleField = Grid1.FindColumn("Roles") as FineUI.BoundField; if (roleField != null) { string roles = ""; foreach (var item in user.Roles) { roles += item.GetDescription() + ","; } roles = roles.TrimEnd(','); roleField.DataFormatString = " " + roles; } }
protected void btn_rePush_Click(object sender, EventArgs e) { try { //是否存在非异常单 CheckBoxField field1 = (CheckBoxField)Grid1.FindColumn("CheckBoxField1"); string sqlCmd = string.Empty; foreach (GridRow row in Grid1.Rows) { int rowIndex = row.RowIndex; bool isSel = field1.GetCheckedState(rowIndex); if (isSel) { string apiState = row.Values[7].ToString();//API状态 int rowID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]); if (apiState != "异常") { continue; } else { sqlCmd = "update sfyordertab set isnew='0' where SOId='" + rowID + "'"; SqlSel_Pro.ExeSql(sqlCmd); } } } Alert.Show("操作成功!"); reBound(); } catch (Exception ex) { Alert.ShowInTop(ex.Message); } }
protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e) { ContractOrderInfo row = e.DataItem as ContractOrderInfo; int isTemp = Convert.ToInt32(row.OrderState); LinkButtonField lbtnEditField = Grid1.FindColumn("lbtnEditField") as LinkButtonField; lbtnEditField.Enabled = isTemp == 1; }
//-------------------------------------------------- // Grid //-------------------------------------------------- // 行绑定事件(BUG: 若是admin则删除按钮无效,代码都对,但整列都变无效了) protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { var item = e.DataItem as DAL.Article; // 设置职务列 var field = Grid1.FindColumn("Type") as FineUI.BoundField; field.DataFormatString = item.Type.GetDescription(); }
protected void Button3_Click(object sender, EventArgs e) { GridColumn genderColumn = Grid1.FindColumn("gender"); genderColumn.Hidden = !genderColumn.Hidden; //GridColumn lastColumn1 = Grid1.Columns[Grid1.Columns.Count - 1]; //GridColumn lastColumn2 = Grid1.Columns[Grid1.Columns.Count - 2]; }
protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e) { LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField; DataTable curDt = getDataTable(); curDt.Rows.RemoveAt(e.RowIndex); Grid1.DataSource = curDt; Grid1.DataBind(); }
/// <summary> /// 列表按键绑定——修改列表控件属性 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { DataRowView row = e.DataItem as DataRowView; if (row != null) { if (row.Row.Table.Rows[e.RowIndex][InformationTable.IsDisplay].ToString() == "0") { var lbf = Grid1.FindColumn("IsDisplay") as LinkButtonField; lbf.Icon = Icon.BulletCross; lbf.CommandArgument = "1"; } else { var lbf = Grid1.FindColumn("IsDisplay") as LinkButtonField; lbf.Icon = Icon.BulletTick; lbf.CommandArgument = "0"; } //绑定是否置顶 if (row.Row.Table.Rows[e.RowIndex][InformationTable.IsTop] .ToString() == "0") { var lbf = Grid1.FindColumn("IsTop") as LinkButtonField; lbf.Icon = Icon.BulletCross; lbf.CommandArgument = "1"; } else { var lbf = Grid1.FindColumn("IsTop") as LinkButtonField; lbf.Icon = Icon.BulletTick; lbf.CommandArgument = "0"; } //绑定是否推荐 if (row.Row.Table.Rows[e.RowIndex][InformationTable.IsHot] .ToString() == "0") { var lbf = Grid1.FindColumn("IsHot") as LinkButtonField; lbf.Icon = Icon.BulletCross; lbf.CommandArgument = "1"; } else { var lbf = Grid1.FindColumn("IsHot") as LinkButtonField; lbf.Icon = Icon.BulletTick; lbf.CommandArgument = "0"; } } //绑定是否编辑列 var lbfEdit = Grid1.FindColumn("ButtonEdit") as LinkButtonField; lbfEdit.Text = "编辑"; lbfEdit.Enabled = MenuInfoBll.GetInstence().CheckControlPower(this, "ButtonEdit"); }
protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e) { Infobasis.Data.DataEntity.HouseInfo houseInfo = e.DataItem as Infobasis.Data.DataEntity.HouseInfo; LinkButtonField deleteField = Grid1.FindColumn("deleteField") as LinkButtonField; // ForbidDelete deleteField.Enabled = true; deleteField.ToolTip = "删除"; }
protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e) { GoodsOrder row = e.DataItem as GoodsOrder; int isTemp = Convert.ToInt32(row.IsTemp); LinkButtonField lbtnEditField = Grid1.FindColumn("lbtnEditField") as LinkButtonField; LinkButtonField deleteField = Grid1.FindColumn("deleteField") as LinkButtonField; lbtnEditField.Enabled = isTemp > 0; deleteField.Enabled = isTemp > 0; }
/// <summary> /// 列表按键绑定——修改列表控件属性 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Grid1_PreRowDataBound(object sender, FineUI.GridPreRowEventArgs e) { //绑定是否显示状态列 int o = e.RowIndex; //绑定是否编辑列 var lbfEdit = Grid1.FindColumn("ButtonEdit") as LinkButtonField; lbfEdit.Text = "编辑"; lbfEdit.Enabled = MenuInfoBll.GetInstence().CheckControlPower(this, "ButtonEdit"); }
private void BindGrid() { //DataTable table = GetDataTable(); //Grid1.DataSource = table; //Grid1.DataBind(); GridColumn column = Grid1.FindColumn(Grid1.SortColumn); BindGridWithSort(column.SortField, Grid1.SortDirection); }
protected void Grid1_PreRowDataBound(object sender, FineUIPro.GridPreRowEventArgs e) { User user = e.DataItem as User; // 不能删除超级管理员 if (user.Name == "admin") { FineUIPro.LinkButtonField deleteField = Grid1.FindColumn("deleteField") as FineUIPro.LinkButtonField; deleteField.Enabled = false; deleteField.ToolTip = "不能删除超级管理员!"; } }
protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e) { if (e.CommandName == "CheckBox1") { CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex); bool checkState = checkField.GetCheckedState(e.RowIndex); Alert.ShowInTop(String.Format("你点击了第 {0} 行,第 {1} 列,选中状态:{2}", e.RowIndex + 1, e.ColumnIndex + 1, checkState)); } else if (e.CommandName == "Action1" || e.CommandName == "Action2") { Alert.ShowInTop(String.Format("你点击了第 {0} 行,第 {1} 列,行命令是 {2}", e.RowIndex + 1, e.ColumnIndex + 1, e.CommandName)); } }
protected void Grid1_PreDataBound(object sender, EventArgs e) { // 设置LinkButtonField的点击客户端事件 LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField; deleteField.OnClientClick = GetDeleteScript(Grid1); PRODUCT00Bll.GetInstence().BandDropDownListShowProductName_1(this, DropDownList1, ""); // (System.Web.UI.WebControls.DropDownList) //DropDownList1.DataTextField = PRODUCT00Table.PROD_NAME1; //DropDownList1.DataValueField = PRODUCT00Table.PROD_ID; // DropDownList1.SelectedValue = ((System.Data.DataRowView)(row)).Row.Table.Rows[e.RowIndex][PRODUCT00Table.PROD_ID].ToString(); }