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

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>";
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值