码迷,mamicode.com
首页 > 其他好文 > 详细

GridView中点击某行的任意位置就选中该行

时间:2017-01-10 17:06:08      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:view   sel   str   string   ring   rgs   command   idv   auto   

 GridView中点击某行的任意位置就选中该行 

分类:

第一步:添加选择列
    点击GridView右边小尖头,双击CommandField,选中"选择",添加,将起设置为不可见;
第二步:处理"ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证",在源文件中添加"enableEventValidation="false"";
第三步:在GridView的RowDataBound事件中增加以下代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
     PostBackOptions myPostBackOptions = new PostBackOptions(this);
     myPostBackOptions.AutoPostBack = false;
     myPostBackOptions.RequiresJavaScriptProtocol = true;
     myPostBackOptions.PerformValidation = false;
     String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$" + e.Row.RowIndex.ToString());
     e.Row.Attributes.Add("onclick", evt);
}
第四步:在GridView的SelectedIndexChanged事件中增加你选中了某行后想做的事:
 protected void dataGridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    //Functions you want to carry out;
}
OK!

 

GridView中点击某行的任意位置就选中该行

标签:view   sel   str   string   ring   rgs   command   idv   auto   

原文地址:http://www.cnblogs.com/cnblogswcl/p/6269668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!