Gridview绑定方法和选择方法的应用
2008-07-08 09:30
447 查看
private void GridViewBind()
{
GridView1.DataSource = 数据源;
GridView1.DataKeyNames = new string[] {"id" };//用数组来指定
GridView1.DataBind();
}
gridview中的一些特效.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//高亮显示指定行
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
//进行时间格式化
e.Row.Cells[5].Text = Convert.ToDateTime(e.Row.Cells[5].Text).ToShortDateString();
//删除指定行数据时,弹出询问对话框
((LinkButton)(e.Row.Cells[8].Controls[0])).Attributes.Add("onclick", "return confirm('是否删除当前行数据!')");
//多余字 使用...显示
//StringFormat.Out是自定义的一个方法,等于substring()
e.Row.Cells[1].Text = StringFormat.Out(e.Row.Cells[2].Text, 7);
e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 16);
}
}
gridview中选择按钮的应用
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
Response.Write("<script> window.open('DetailLeaguerInfo.aspx?id=" + id + "','','scrollbars') </script>");
Response.Write("<script>history.go(-1)</script>");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//高亮显示指定行
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
//设置审核状态,并且设置相应的颜色。
if (e.Row.Cells[5].Text == "False")
{
e.Row.Cells[5].Text =StringFormat.HighLight("未审核",true);
}
else
{
e.Row.Cells[5].Text = StringFormat.HighLight("已审核", false);
}
//多余字 使用...显示
e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 18);
}
{
GridView1.DataSource = 数据源;
GridView1.DataKeyNames = new string[] {"id" };//用数组来指定
GridView1.DataBind();
}
gridview中的一些特效.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//高亮显示指定行
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
//进行时间格式化
e.Row.Cells[5].Text = Convert.ToDateTime(e.Row.Cells[5].Text).ToShortDateString();
//删除指定行数据时,弹出询问对话框
((LinkButton)(e.Row.Cells[8].Controls[0])).Attributes.Add("onclick", "return confirm('是否删除当前行数据!')");
//多余字 使用...显示
//StringFormat.Out是自定义的一个方法,等于substring()
e.Row.Cells[1].Text = StringFormat.Out(e.Row.Cells[2].Text, 7);
e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 16);
}
}
gridview中选择按钮的应用
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
Response.Write("<script> window.open('DetailLeaguerInfo.aspx?id=" + id + "','','scrollbars') </script>");
Response.Write("<script>history.go(-1)</script>");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//高亮显示指定行
e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
//设置审核状态,并且设置相应的颜色。
if (e.Row.Cells[5].Text == "False")
{
e.Row.Cells[5].Text =StringFormat.HighLight("未审核",true);
}
else
{
e.Row.Cells[5].Text = StringFormat.HighLight("已审核", false);
}
//多余字 使用...显示
e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 18);
}
相关文章推荐
- ASP.Net应用深入系列(一):GridView行绑定时取得某个数据列的几种方法比较
- ASP.Net应用深入系列(一):GridView行绑定时取得某个数据列的几种方法比较
- 改变gridview绑定列值的方法
- 转 gridview中绑定dropdownlist的最简单方法!!
- 改变gridview绑定列值的方法
- gridview绑定checkbox控件后,通过单击CheckedChanged事件获取当前选择行的数据
- Gridview 获取隐藏列中绑定值方法
- JQuery入门总结(二)【选择器、方法应用】
- go语言使用go-sciter创建桌面应用(七) view对象常用方法,文件选择,窗口弹出,请求
- Android--GridView/ListView 点击Item修改Item背景 标识是当前选择项方法
- 选择gridview1中的某几行,赋值到datatable中 并绑定到另一个的gridview2
- 选择好适合自已的数据绑定方法!
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- GridView绑定数据的方法
- 前台用Gridview绑定数据时时间只显示 年月日 的方法
- [原创]Asp.Net中GridView缩略字符串绑定的方法
- asp.net遍历文件夹下所有子文件夹并绑定到gridview上的方法
- 在gridview的行绑定中应用AnimationExtender效果
- 自定义DataList,GridView通过DataBinder.Eval方法绑定的数据
- GridView应用实例(包括添加、删除、更新以及DropDownList的绑定)转