首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请问一个GridView 有关问题.

2011-12-29 
请教一个GridView 问题...怎么实现点击GridView行调用OnRowCommand事件...我想点击行的任意地方都可以进入

请教一个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() ");
}
}
}

热点排行