您的位置:首页 > 编程语言 > C#

C#语法基础巩固

2015-12-03 19:39 211 查看
1、protected void Button1_Click(object sender, EventArgs e)

protected 关键字是一个成员访问修饰符。受保护成员在它的类中可访问并且可由派生类访问
void表示该方法没有返回类型
Button1_Click这是按钮1的点击事件
object sender表示的是Objece类型的参数
EventArgs表示的是事件源

object sender 触发这个函数发生的对象
EventArgs e 事件相关参数数据 你要为一个事件写一个响应函数,你需要什么?
1.是谁触发的:你可以把三个按钮的点击事件都指定为一个响应函数,但是你要是做出不同反应怎么办?区分sender看是哪个按钮。
2.触发的是什么事件,这个事情的详细情况是什么:这里边包含着事件能提供的附属信息
可以理解下下面方法中的 e 所起的作用
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//删除时的确定
(e.Row.Cells[6].Controls[0] as LinkButton).Attributes.Add("onclick","return confirm('确定删除?');");
//实现光棒效果
e.Row.Attributes.Add("onmouseover","this.bgColor='#ee00ee';");
e.Row.Attributes.Add("onmouseout", "this.bgColor='#ffffff';");
//如果编辑的索引和当前你选的行的索引相同
if (GridView1.EditIndex == e.Row.RowIndex)
{
//找到下拉列表控件(注意是该控件的ID)
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;
//(e.Row.DataItem)来获得当前这一行数据所对应的实体类对象
Entity entity= (e.Row.DataItem as Entity); //ddl.ClearSelection();
//在下拉列表中找到该对象的学历并选中
ddl.Items.FindByText(worker.WorkStudyLevel).Selected = true;
FileUpload fu = e.Row.FindControl("FileUpload1") as FileUpload;
//通过属性中杂项找到id
Image hi = e.Row.FindControl("Image1") as Image;
string scriptStr = "SetImage(this.value,'name');";
scriptStr = scriptStr.Replace("name",hi.ClientID);
fu.Attributes.Add("onchange", scriptStr);
//fu.Attributes.Add("onchange", "SetImage(this.value,'"+hi.ClientID+"');");与上一样
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: