All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET构架与安全机制之Http请求处理_.net资料_编程技术
基于AJAX.NET技术的DataGrid控件开发_[Asp.Net教程]
通俗的最新PHP类的使用和归纳_[PHP教程]
ASP.NET实现匿名访问控制_[Asp.Net教程]
asp.net验证码控件_[Asp.Net教程]
每个开发人员现在应该下载的十种必备工具,1_[Asp.Net教程]
C#中定义鼠标指针为指定的动画图标实例
C#教程:C#调用动态链接库
c#远程获取网页内容_.net资料_编程技术
PHP多文件上传类_[PHP教程]
Reading number is top 10 pictures
含苞欲放的素颜美少女1
Perfect small Laurie2
A man's favorite things4
王艳写真温柔如水1
Fan bingbing black wings for platform and DanLuoWang believes beauty1
China's first snake village2
From China fortress sora aoi4
A man's favorite things16
Sora aoi mirror memorial classics2
餐桌上的鱼
Download software ranking
C#编程思想
Tram sex maniac 2 (H) rar bag17
美女写真2
Wild things 2
SQL2000 For 4IN1
Desire a peach blossom
传奇私服架设教程
变速齿轮3.26
C#COM编程指南
Jinling thirteen stock
delv published in(发表于) 2014/1/6 9:07:19 Edit(编辑)
GridView中利用隐藏的TemplateFied来进行数据访问_[Asp.Net教程]

GridView中利用隐藏的TemplateFied来进行数据访问_[Asp.Net教程]

GridView中利用隐藏的TemplateFied来进行数据访问_[Asp.Net教程]

在上一个学习随笔中我们可以利用DataKeyNames和DataKeys来进行GridView主键列的数据访问, 在后来试验中,我发现我们可以利用TemplateField来实现其他的数据访问.






//后台实现


String userName = ((Literal)GridView1.SelectedRow.FindControl("litUserName")).Text;
GridView的AutoGenerateSelectButton属性可以直接使表格实现选择, 如果不想多增加一列选择列, 我们可以利用TemplateField实现GridView的选择.


ASP.NET代码如下:





Name



<%#Eval("Name")%>




同时要给GridView增加两个事件处理RowCreated, RowCommand
//RowCreated事件处理
void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ ((LinkButton)e.Row.FindControl("lbName")).CommandArgument = e.Row.RowIndex.ToString();
}
}
//RowCommand事件处理
void GridView1_RowCommand(object source, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
GridView1.SelectedIndex = int.Parse(e.CommandArgument.ToString());
}


这样在点击名称时就可以同时进行选择,不必再利用选择列.


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.