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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 豆丁不想长大

CheckBoxList与表的操作 - 豆丁不想长大 - 博客园 判断用户浏览器类型的代码 - 豆丁不想长大 - 博客园 GridView的RowdataBound事件 后台代码创建Table javascript循环判断Radio是否选中 - 豆丁不想长大 - 博客园 不错的韩剧 19根烟忘却你的理由 28句朴素的道白 Web.config详解 - 豆丁不想长大 - 博客园 忘记密码发送邮件提醒的代码 弹出对话框后转到下一页的代码 后台编写返回上一页的代码 FindControl的作用 ASP.net2.0学习资料汇总 星巴克咖啡价格 ASP.NET 常用代码 MessageBox的CS文件中的写法 Split的用法 关于DDL控件提交后刷新问题
Gridview中的DataKeys問題
豆丁不想长大 · 2007-01-31 · via 博客园 - 豆丁不想长大

首先,請先把你的 ButtonField 轉換成 TemplateField,把它改成如下的樣子:

<Columns>
    <asp:TemplateField ShowHeader="False">
        <ItemTemplate>
            <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="Details"
                CommandArgument='<%# Eval("OrderID") %>' Text="Details" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="OrderID" HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" />
    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" />
    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" />
    <asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
    ...
</Columns>

注意 CommandArgument='<%# Eval("OrderID") %>' 這句必須手動加上去。把 OrderID 改名成你的欄位名稱。

接著,請修改 GridView1_RowCommand() 如下:

    Protected Sub GridView1_RowCommand(...) Handles GridView1.RowCommand
        If e.CommandName = "Details" Then
            Response.Redirect(String.Format("Default.aspx?ID={0}", e.CommandArgument))
        End If
    End Sub