DataGrid应用
1、提示+鼠标经过颜色
private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach(System.Web.UI.WebControls.HyperLink link in e.Item.Cells[7].Controls)
{
link.Attributes.Add("onClick","if (!window.confirm('您真的要删除这条记录吗?')){return false;}");
}
if(e.Item.ItemIndex>=0)
{
string title=Application[Session["Style"].ToString()+"xtable_titlebgcolor"].ToString();
string bgcolor=Application[Session["Style"].ToString()+"xtable_bgcolor"].ToString();
e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='"+title+"'; this.style.cursor='hand';");
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='"+bgcolor+"';");
}
}
2、有删除的绑定与分页
private void Bind()
{
this.dgInfo.DataSource=IOrg.GetList(this.drpList.SelectedItem.Value,this.txtSearch.Text):IOrg.GetSingleList(Session["org_o_id"].ToString());
try
{
this.dgInfo.DataBind();
}
catch
{
this.dgInfo.CurrentPageIndex=0;
this.dgInfo.DataBind();
}
}
private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach(System.Web.UI.WebControls.HyperLink link in e.Item.Cells[7].Controls)
{
link.Attributes.Add("onClick","if (!window.confirm('您真的要删除这条记录吗?')){return false;}");
}
if(e.Item.ItemIndex>=0)
{
string title=Application[Session["Style"].ToString()+"xtable_titlebgcolor"].ToString();
string bgcolor=Application[Session["Style"].ToString()+"xtable_bgcolor"].ToString();
e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='"+title+"'; this.style.cursor='hand';");
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='"+bgcolor+"';");
}
}
2、有删除的绑定与分页
private void Bind()
{
this.dgInfo.DataSource=IOrg.GetList(this.drpList.SelectedItem.Value,this.txtSearch.Text):IOrg.GetSingleList(Session["org_o_id"].ToString());
try
{
this.dgInfo.DataBind();
}
catch
{
this.dgInfo.CurrentPageIndex=0;
this.dgInfo.DataBind();
}
}