您的位置:首页 > 其它

GridView相关总结(主键绑定 行高亮 状态替换 多余字符...替代 详情查看 )

2014-01-05 14:43 411 查看
1.GridView控件绑定并添加主键

public void GVInfoBand()

    {

        gvInfoShow.DataSource = op.SelectInfo();
        gvInfoShow.DataKeyNames = new string[] { "id" };//为GridView主键绑定

        gvInfoShow.DataBind();

    }

2.GridView控件行绑定数据事件

protected void gvInfoShow_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        //当前行为数据绑定行

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            //选中行高亮显示 行高亮 

            e.Row.Attributes.Add("onMouseOver", "color=this.style.backgroundColor;this.style.backgroundColor='#f0f0f0';");

            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);

            //信息详情列绑定  获取选中行的主键  详情查看

            e.Row.Cells[6].Text = "<a href='LookInfo.aspx?info_id="+this.gvInfoShow.DataKeys[e.Row.RowIndex].Value.ToString()+"'>查看详情</a>";

        }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: