ASP.NET 中gridview取消点击效果点击一行显示详细信息

[转][ASP.NET]GridView点击行触发SelectedIndexChanged事件
好东东 收藏
@Page&......&%&指令中添加
EnableEventValidation="false"
2、在RowDataBound事件中添加
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
&&&&&&&&switch (e.Row.RowType)
&&&&&&&&&&&
case DataControlRowType.DataRow:
&&&&&&&&&&&&&&&
e.Row.Attributes["style"] = "cursor:hand";
&&&&&&&&&&&&&&&
//点击行触发SelectedIndexChanged事件
&&&&&&&&&&&&&&&
PostBackOptions myPostBackOptions = new
PostBackOptions(this);
&&&&&&&&&&&&&&&
myPostBackOptions.AutoPostBack =
&&&&&&&&&&&&&&&
myPostBackOptions.PerformValidation =
&&&&&&&&&&&&&&&
myPostBackOptions.RequiresJavaScriptProtocol =
//加入javascript:头
&&&&&&&&&&&&&&&
String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as
GridView, "Select$" + e.Row.RowIndex.ToString());
&&&&&&&&&&&&&&&
e.Row.Attributes.Add("onclick",
&&&&&&&&&&&&&&&
#endregion
&&&&&&&&&&&&&&&
3、在第一二步之后就可以在SelectedIndexChanging和SelectedIndexChanged事件中添加处理逻辑了。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'\t\tASP.NET 通过DIV显示GridView中每行的图片 1/2',
blogAbstract:'1.前台代码:&%...@ Control Language=&C#& AutoEventWireup=&true& CodeFile=&ImageControl.ascx.cs& Inherits=&usercontrol_ImageControl& %&&%...@ Register Src=&FolderTree.ascx& TagName=&FolderTree& TagPrefix=&uc2& %&&%...@ Register Src=&DepartPageControl.ascx& TagName=&DepartPageControl& TagPrefix=&uc1& %&',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:4,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}新浪广告共享计划>
广告共享计划
asp.net2005GridView控件的选择行问题.单击一行即选中行(象新浪博客文章管理)
GridView控件加了选择列,单击"选择"可以选择某一列.
但我现在想单击一行中的任意位置都可以选择一行,并不只单单限制必须点击"选择"列
怎么办呢?
分析源码:
在GridView中加入一个按钮,CommandName为Select。如下
&asp:ButtonField
CommandName="Select" Text="Button" /&
运行后查看源码:
href="javascript:__doPostBack 'GridView1','Select$0')"&Button&/a&
href="javascript:__doPostBack('GridView1','Select$1')"&Button&/a&
'GridView1'为GridView控件的ID
'Select为CommandName
0'为当前行
由此可知,只要在单击列时调用javascript:__doPostBack('GridView名称','Select$当前行')"&就行了,注:行数从0开始计数。
可得代码如下:
protected void GridView1_Load(object
sender, EventArgs e)
for (int i = 0; i & this.GridView1.Rows.C i++)
&&&&&&&&&&&
this.GridView1.Rows[i].Attributes.Add("onclick",
"javascript:__doPostBack('GridView1','Select$" +i.ToString
同理可做出Edit、Delete等应用
以上代码在
Microsoft Visual Studio 2005
Version 8.0.50727.42& (RTM.0)
Microsoft .NET Framework
Version 2.0.50727
Installed Edition: WD
Microsoft Visual Web Developer
Microsoft Visual Web Developer 2005
上测试通过。
也有一说VS2005上出来的代码不一样:
选择列调用的函数有如下特点,href="javascript:__doPostBack('GridView1$ctl05$LinkButton1','')"事实上是把选择列的客户端控件名的"_"替换成"$"然后调用:__doPostBack()函数的,所以我想,如果先得到选择列的客户端ID把"_"替换成"$"就可以了,所以用在页面加载完成后再逐行加客户端onclick事件,
如protected void GridView1_Load(object sender, EventArgs e)
for (int i = 0; i & this.GridView1.Rows.C i++)
this.GridView1.Rows[i].Attributes.Add("onclick","javascript:__doPostBack('"+
this.GridView1.Rows[i].FindControl("LinkButton1").ClientID.Replace("_","$")+"','')");
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 gridview点击item事件 的文章

 

随机推荐