GridView操作_转www_sw的专栏
来源:互联网 发布:android 网络通信方式 编辑:程序博客网 时间:2024/05/20 22:03
1、鼠标悬停变色
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
//为特定的数改变行样式这也是在这个事件里面,因为这个事件是在数据被绑定的时候执行的
for (int i = 0; i < GridView1.Rows.Count; i++)
{ //为了对全部数据行都有用,我们使用循环
string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem,"state"));//我们得取出行中state字段绑定的值,用他作为判断条件
if (lbl == "BB")
{ //如果他的值等于BB,那么
e.Row.BackColor = Color.LimeGreen;//
}
}
}
}
2、隐藏、显示列
protected void Button1_Click(object sender, EventArgs e)
{//隐藏特定的列
int r = int.Parse(TextBox1.Text);
GridView1.Columns[r].Visible = false;
}
protected void Button2_Click(object sender, EventArgs e)
{//显示全部被隐藏的列
for (int j = 0; j < GridView1.Columns.Count; j++)
{//循环所有的列,然后检察属性是否是否,如果是就改变成是就可以了
if (GridView1.Columns[j].Visible == false)//刚才错在判断这里了,呵呵
{
GridView1.Columns[j].Visible = true;
}
}
3、分页
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
DataBind1();
}
public void DataBind1()
{
SqlConnection con = DB.createCon();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from province", con);
DataSet ds = new DataSet();
sda.Fill(ds, "province");
this.GridView1.DataSource = ds.Tables["province"];
this.GridView1.DataBind();
}
设置属性AllowPaging为true
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/www_sw/archive/2009/05/15/4189807.aspx
- GridView操作_转www_sw的专栏
- GridView专栏
- CString 操作指南 - pinping1314的专栏 - CSDNBlog
- GridView的常用操作
- GridView的几个操作
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的操作大全
- GridView的基本操作
- GridView的操作大全
- C语言宏定义运用技巧
- Struts2结果类型(Result Types)
- Struts 2之HelloWorld(下)
- 粗粒度与细粒度
- 得到已知结点下的所有字结点
- GridView操作_转www_sw的专栏
- 程式開發質量檢查(十)
- 奇数阶幻方
- 如何使用xFire开发webService返回复杂对象List
- hciconfig
- qweqwe
- webservice-XFire开发一个简单的web服务
- Pencil Case
- XFire开发webservice服务和客户端全攻略