<实现鼠标滑过背景色改变>
RowDataBound事件
if(e.Row.RowType==DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;"
+" this.style.backgroundColor=='pink';");
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c");
}
<模板列DropDowList动态绑定数据>不能再绑定数据源了因为已经是DataBinding事件
编辑模板--->选择DropDownList1控件 找到 DataBinding事件
DropDownList ddl(DropDownList)sender;
ddl.Items.Add(new ListItem("True"));
ddl.Items.Add(new ListItem("False"));
2.如果是绑定数据库字段
DropDownList ddl(DropDownList)sender;
ddl.DataTextField="cityName";
ddl.DataValueField="cityID";
<让GridView失去光标>
GridView1.EditIndex=-1;
然后从新绑定数据
<编辑按钮,实现 编辑 和 删除 和 修改 和 取消选择>
在模板列中,设置CommandName 分别为Edit Delete Update Cancel
1.Edit 自动回触发 RowEditing事件
GridView2.EditIndex=e.NewEditIndex;
从新绑定数据GridView1
2.Update 自动触发 RowUpdating事件
int index=e.RowIndex;
string id=GridView2.DataKeys[index].Value.ToString();
string name=((TextBox)GridView2.Row[index].FindControl("txtName")).Text;
3.Delete 自动触发RowDeleting事件
int index=e.RowIndex;
string id=GridView2.DataKeys[index].Value.ToString();
4.Cancel 自动触发
GridView.EditIndex=-1;
从新绑定GridView
posted on
浙公网安备 33010602011771号