单击GridView的某一行 根据此行id得到这行的所有信息
2011-03-11 16:23
281 查看
1.在源的第一行<%@ Page ....%>中添加 EnableEventValidation="false"
2.
注意项:若根据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();
}
}
}
2.
注意项:若根据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();
}
}
}
相关文章推荐
- sql如何根据父级Id得到所有下级的记录
- java递归根据节点ID得到所有父节点名称
- 根据某个部门ID递归获取其下面所有子部门和本部门信息
- 实现单击tree的子节点得到其所有父节点的id呢
- 获取所有用户表及根据表Id取得表字段信息
- 根据类名得到类的所有信息
- Linux+树莓派3开发总结——根据设备ID等信息固定串口号
- gridview repeater 根据(分类id列出分类名)
- 如何根据Correlation ID来查找具体的错误信息
- PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中
- IOS_根据Bundle ID 唤醒App(获取手机里所有APP包名)
- ASP.NET中GridView单击一行变色并可互斥代码[测试有效!!]
- sql递归查询 根据Id查所有子结点
- SQL Server2005中得到所有表的字段及其他信息
- 存储过程里添加信息到第一个表时得到第一个表的新增ID,并用此ID添加信息到第二个表
- 7.OAut认证 根据授权码获取用户的ID,SECRET等信息
- 【java】根据开始时间、结束时间得到两个时间段内所有的日期
- PHPCMS V9 自定义函数——根据模型ID和信息ID获取信息点击数
- 根据控件Id得到控件并对该控件进行操作
- 根据isbn获得图书的所有信息