日期:2014-05-19  浏览次数:20480 次

求GridView 控件直接单击行选中行,提交的时候可以取得当前选中行的值的代码?
如题,请教各位!

------解决方案--------------------
放到DataKeyNames属性中的字段:
GridView1.DataKeys[nIndex].Value // 仅一个主键的情况

GridView1.DataKeys[nIndex].Values // 多个

其它字段就需要从数据库查询,或者
GridView1.Rows[nIndex].Cells[i].Text了
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标移动到每项时颜色交替效果
e.Row.Attributes.Add( "OnMouseOut ", "out(this); ");
e.Row.Attributes.Add( "OnMouseOver ", "over(this,this.style.backgroundColor); ");

//单击/双击 事件
e.Row.Attributes.Add( "OnDblClick ", "DbClickEvent(this, ' " + getDb(e.Row.RowIndex) + " ', ' " + e.Row.Cells[2].Text + " ', ' " + dqbm + " '); ");

//设置悬浮鼠标指针形状为 "小手 "
e.Row.Attributes[ "style "] = "Cursor:hand ";

e.Row.Attributes.Add( "onClick ", "this ");

CheckBox cb = new CheckBox();
cb = (CheckBox)e.Row.FindControl( "CheckBox1 ");
if (cb != null)
{
cb.Attributes.Add( "onClick ", "changecolor(this); ");
}

}
}
给GridView加上checkbox,在GridView的绑定事件里。给每行加上单击或双击的事件
在角本事件里就可以用这些值了。
------解决方案--------------------
function DbClickEvent(obj,value1,value2,value3)
{
if(value2!= "【无参数】 ")
{
var re =showModalDialog( 'paraEdit.aspx?strxg= '+value1+ '&dqbm= '+value3, ' ', 'dialogleft:125px; dialogtop:50px; dialogheight:640px; dialogwidth:750px;scroll:no;status:no;help:no; ');

if(re== 'true ')
{
window.document.location.href=window.document.location.href;
}
}
}
是个角本的双击事件function