单击GridView的某一行 根据此行id得到这行的所有信息

1.在源的第一行<%@ Page ....%>中添加 EnableEventValidation="false"
2.2011031416174133.jpg注意项:若根据id得到点击行的详细信息 则id必须存在GridView中,用隐藏控件接收id的值 如图

3.在GridView1_RowDataBound事件中写入行的onclick事件
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[3].Text = e.Row.Cells[3].Text.ToString().Substring(0, 8) + "......";
            ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "return confirm('是否要删除此

行?')");
            e.Row.Attributes["OnClick"] =ClientScript.GetPostBackEventReference(e.Row.Parent.Parent, "Select$" +

e.Row.RowIndex);
            //e.Row.Attributes.Add("onclick", "t=this.style.backgroundColor;this.style.backgroundColor='#ebebce'");
            //e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=t");
            //e.Row.Attributes.CssStyle.Add("cursor", "hand");

        }
    }
4.在GridView1_SelectedIndexChanged中写点击行的代码
  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridView grv = (GridView)sender;
        if (grv.SelectedRow.RowType == DataControlRowType.DataRow)
        {
            if (grv.SelectedIndex != -1)
            {
                int id =Convert.ToInt32(((HiddenField)grv.Rows[grv.SelectedIndex].FindControl("idd")).Value.ToString());
                DataSet ds = op.SelectInfo("招聘信息", id);
                DataTable dt = ds.Tables[0];
                TextBox1.Text = dt.Rows[0][0].ToString();
            }
        }
    }

转载于:https://www.cnblogs.com/MyBeN/archive/2011/03/11/1981553.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值