/// <summary> /// 数据列表项绑定事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void DataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover", "this.className='mouseoverstyle'"); e.Item.Attributes.Add("onmouseout", "this.className='mouseoutstyle'"); e.Item.Style["cursor"] = "hand"; //e.Item.Cells[3].Attributes.Add("onclick", "alert('你点击的ID是: " + e.Item.Cells[0].Text + "!');"); } if (!this.SaveDSViewState) { this.Controls[0].EnableViewState = false; } if (this.IsFixConlumnControls) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //int count=0; for (int i = 0; i < e.Item.Cells.Count; i++) { if ((!e.Item.Cells[i].HasControls())) { if (GetBoundColumnFieldReadOnly()[i].ToString().ToLower() == "false") //判断是否存在只读属性 { System.Web.UI.WebControls.TextBox t = new System.Web.UI.WebControls.TextBox(); t.ID = GetBoundColumnField()[i].ToString(); t.Attributes.Add("onmouseover", "if(this.className != 'FormFocus') this.className='FormBase'"); t.Attributes.Add("onmouseout", "if(this.className != 'FormFocus') this.className='formnoborder'"); t.Attributes.Add("onfocus", "this.className='FormFocus';"); t.Attributes.Add("onblur", "this.className='formnoborder';"); t.Attributes.Add("class", "formnoborder"); t.Text = e.Item.Cells[i].Text.Trim().Replace(" ", ""); //设置宽度 if (this.Columns[i].ItemStyle.Width.Value > 0) { t.Width = (int)this.Columns[i].ItemStyle.Width.Value; } else { t.Width = 100; } e.Item.Cells[i].Controls.Add(t); } } else { foreach (System.Web.UI.Control c in e.Item.Cells[i].Controls) { //加载discuz下拉控件 if (c is Discuz.Control.DropDownList) { Discuz.Control.DropDownList __dropdownlist = (Discuz.Control.DropDownList)c; if (__dropdownlist.SqlText != "") { __dropdownlist.AddTableData(__dropdownlist.SqlText); } try { __dropdownlist.SelectedValue = Convert.ToString(DataBinder.Eval(e.Item.DataItem, __dropdownlist.DataValueField)); } catch {; } } //加载普通下拉控件 if (c is System.Web.UI.WebControls.DropDownList) { System.Web.UI.WebControls.DropDownList __dropdownlist = (System.Web.UI.WebControls.DropDownList)c; try { __dropdownlist.SelectedValue = Convert.ToString(DataBinder.Eval(e.Item.DataItem, __dropdownlist.DataValueField)); } catch {; } } } } // count++; } } } else { if (e.Item.ItemType == ListItemType.EditItem) { for (int i = 0; i < e.Item.Cells.Count; i++) { e.Item.Cells[i].BorderWidth = 1; e.Item.Cells[i].BorderStyle = BorderStyle.Solid; e.Item.Cells[i].BorderColor = System.Drawing.Color.FromArgb(234, 233, 225); if (e.Item.Cells[i].HasControls()) { for (int j = 0; j < e.Item.Cells[i].Controls.Count; j++) { System.Web.UI.WebControls.TextBox t = e.Item.Cells[i].Controls[j] as System.Web.UI.WebControls.TextBox; if (t != null) { t.Attributes.Add("onfocus", "this.className='FormFocus';"); t.Attributes.Add("onblur", "this.className='FormBase';"); t.Attributes.Add("class", "FormBase"); } } } } } } }