private void CellEdit() { GetColInfo(); string RowDataKey = Request.Params["dataKey"]; string EditValue = Request.Params["value"]; string EditColName = Request.Params["colName"]; string EditCellIndex = Request.Params["cellIndex"]; CellEditEventArg Args = new CellEditEventArg(); Args.ColName = EditColName; Args.Value = EditValue; Args.DataKey = RowDataKey; Args.KeyName = this.DataKey; Args.CellIndex = Convert.ToInt32(EditCellIndex); if (OnCellEdit != null) { OnCellEdit(this, Args); } Response.Clear(); Response.ContentType = "application/json"; StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"error\":" + (Args.Error == null ? "null" : "\"" + Args.Error + "\"")); sb.Append("}"); Response.Write(sb.ToString()); Response.Flush(); Response.End(); }
public override void DataBind() { DataTable dt = this.DataSource; List <ColInfo> cols = this.Columns; if (dt != null && dt.Rows.Count > 0) { HtmlGenericControl tbodyPanal = new HtmlGenericControl("div"); tbodyPanal.Attributes.Add("class", "datagrid-tbody-panal"); // tbodyPanal.Style.Add("height", this.Height); tbody.CellPadding = 0; tbody.CellSpacing = 0; tbody.ID = "tbody"; tbody.Attributes.Add("class", "datagrid-tbody-table"); // tbody.Attributes.Add("rules", "all"); //绑定数据源 for (int i = 0; i < dt.Rows.Count; i++) { string dataKey = dt.Rows[i][this.DataKey].ToString(); HtmlTableRow row = new HtmlTableRow(); row.Attributes.Add("dataKey", dataKey); row.Attributes.Add("rowType", "dataRow"); row.Attributes.Add("class", i % 2 == 0 ? "roweven" : "rowodd"); if (this.ShowCheckColumn == true) { HtmlTableCell checkcell = new HtmlTableCell(); checkcell.Style.Add("width", this.checkWidth + "px"); HtmlInputCheckBox box = new HtmlInputCheckBox(); box.Attributes.Add("multiCheck", "true"); //box.Attributes.Add("onclick", ""); checkcell.Controls.Add(box); row.Controls.Add(checkcell); } for (int j = 0; j < cols.Count; j++) { string txt = dt.Rows[i][cols[j].Field].ToString(); HtmlTableCell cell = new HtmlTableCell(); //设置宽度 int w = cols[j].Width; cell.Style.Add("width", w + "px"); if (cols[j].Full == true) { cell.Attributes.Add("fullColumn", "true"); } if (cols[j].Align != "") { cell.Style.Add("text-align", cols[j].Align); } Enums.ControlType editType = cols[j].EditType; HtmlGenericControl cellChild = new HtmlGenericControl("div"); cellChild.Attributes.Add("class", "datagrid-tbody-cellChild datagrid-cell-nowrap" + (editType == Enums.ControlType.None ? "" : " editor")); //装进文本 HtmlGenericControl celltxt = new HtmlGenericControl("span"); celltxt.InnerHtml = txt; celltxt.ID = Utils.GetGuid; cellChild.Controls.Add(celltxt); //是否可以编辑 string colName = cols[j].Field; if (editType != Enums.ControlType.None) { cellChild.Attributes.Add("editType", editType.ToString()); cellChild.Attributes.Add("colName", colName); cellChild.Attributes.Add("onclick", "$(this).datagridEditStart();"); //文本框 if (editType == Enums.ControlType.Text) { HtmlInputText textbox = new HtmlInputText(); textbox.Attributes.Add("class", "text datagrid-editinput"); cellChild.Controls.Add(textbox); textbox.Attributes.Add("onblur", "$(this).datagridEditEnd();"); textbox.Attributes.Add("onchange", "$(this).datagridEditSave();"); } } cell.Controls.Add(cellChild); //执行单元格创建完毕事件 if (this.OnCellCreated != null) { CellEditEventArg arg = new CellEditEventArg(); arg.ColName = cols[j].Field; arg.DataKey = dataKey; arg.Value = txt; this.OnCellCreated(this, arg); } row.Controls.Add(cell); } tbody.Controls.Add(row); } tbody.Style.Add("width", tableWidth + "px"); tbodyPanal.Controls.Add(tbody); this.GridPanal.Controls.Add(tbodyPanal); } else { //显示空表体 } }