62,046
社区成员
发帖
与我相关
我的任务
分享
#region 样式的控制
protected void GVAffiche_RowDataBound(object sender, GridViewRowEventArgs e)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当有编辑列时,避免出错,要加的RowState判断
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((Button)e.Row.Cells[7].FindControl("btnDel")).Attributes.Add("onclick","javascript:return confirm('你确认删除:\"" + e.Row.Cells[1].Text + "\"')");
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=color");
GVAffiche.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
//GVAffiche.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
if (e.Row.Cells[1].Text == "444")
{
e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
}
}
}
}
#endregion
选中Grid View 的实现
#region实现选中行
<SelectedRowStyle BackColor="AliceBlue" ForeColor="Gray" />
<asp:CommandField ShowSelectButton="True"/>
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "this.cells[0].childNodes[0].click()");
}
protected void GridViewRegiment_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridViewRegiment.SelectedRow;
int RegimentID = Convert.ToInt32(row.Cells[1].Text);
Response.Redirect("UpdateRegimentation.aspx?RegimentID=" + RegimentID);
}
#endregion
显示颜色和删除
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//int i;
//for (i = 0; i < GridViewRegiment.Rows.Count; i++)
//{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当有编辑列时,避免出错,要加的RowState判断
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((ImageButton)e.Row.Cells[2].FindControl("IBtndelete")).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");
}
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E6F5FA'");
}
//}
}
选中Grid View 的实现
#region实现选中行
<SelectedRowStyle BackColor="AliceBlue" ForeColor="Gray" />
<asp:CommandField ShowSelectButton="True"/>
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "this.cells[0].childNodes[0].click()");
}
protected void GridViewRegiment_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridViewRegiment.SelectedRow;
int RegimentID = Convert.ToInt32(row.Cells[1].Text);
Response.Redirect("UpdateRegimentation.aspx?RegimentID=" + RegimentID);
}
#endregion