惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence
IT之家
IT之家
博客园 - 【当耐特】
U
Unit 42
云风的 BLOG
云风的 BLOG
L
LangChain Blog
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium

博客园 - 神话

C#的float型,竟然与SQL中float型不对应(转载) 【源码】非常有用的Vml图像画板(收藏) 为Html 的Select 加一个提示语和输入方法(转载) asp.net三色交替的下拉列表框(转载) 常用正则表达式(收藏) ListBox控件上移、下移操作(Ajax) 客户端实现PadLeft 日历控件收藏 我的博客地图脚本代码 实时统计输入字符数 我的博客地图特效 生成html页面 初次使用ZedGraph 梅花雪日历控件(网络收藏) 树型菜单<仿QQ型菜单>(网络收藏) 面向对象分析(网络收藏) 常用正则表达式(收集)及使用方法 三层架构(非原创) 网页常用代码小技巧五(网络收藏)
获取某行的字段ID值(GridView模板列)
神话 · 2007-06-15 · via 博客园 - 神话

aspx页面

<asp:GridView runat="server" ID="grd" AutoGenerateColumns="false" DataKeyNames="leagueID" OnRowCommand="grd_RowCommand"  OnRowCreated="grd_RowCreated">
<Columns>
<asp:TemplateField HeaderText="我要加入">
                    
<ItemStyle HorizontalAlign="Center" />
                    
<ItemTemplate>
                        
&nbsp;<asp:Button runat="server" ID="btnJoin" Text="加 入" CommandName="btnJoin" />
                    
</ItemTemplate>
                 
</asp:TemplateField>
</Columns>
</asp:GridView>

aspx.cs类文件

 protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
    
{
        
if (e.CommandName == "btnJoin")
        
{
                
int index = Data.GetInt(e.CommandArgument);
                
int iLeagueID = Data.GetInt(grd.DataKeys[index].Value);
                Response.Write(
"<script>alert('" + iLeagueID + "')</script>");
        }

    }


    
protected void grd_RowCreated(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
        
{
                Button btnJoin 
= (Button)e.Row.FindControl("btnJoin");
                btnJoin.CommandArgument 
= e.Row.RowIndex.ToString();
        }

    }