日期:2014-05-18  浏览次数:20379 次

请教一个GridView 问题...
怎么实现点击GridView行调用OnRowCommand事件...
我想点击行的任意地方都可以进入到修改页面...谢谢~~各位

------解决方案--------------------
如果是打开新页面,大致代码如下

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add( "onclick ", "window.open( 'Details.aspx?id= " + this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + " '); ");
}
}
------解决方案--------------------
1。
有个问题..有些参数在绑定事件是取不到的啊
======================
绑定的事件中,就可以取道的,我看行

2。
只有在Commond时才知道指定行的字段值
=============
简直是多此一举,直接通过 链接方式 打开,要是真的取不到,我宁可跳到新页面去再取
------解决方案--------------------
0列放个编辑按钮然后
protected void gvLoans_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Pager)
e.Row.Cells[0].Attributes.Add( "style ", "display:none ");
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 2; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add( "onClick ", "this.parentElement.cells[0].childNodes[0].click() ");
}
}
}