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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
博客园 - 司徒正美
J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
D
Docker
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
I
InfoQ
雷峰网
雷峰网
The Cloudflare Blog
美团技术团队
Engineering at Meta
Engineering at Meta

博客园 - 释天

4年后新的开始 flash make things move 电子书 破解pubwin ep html学习笔记(-) js学习笔记(-) - 释天 - 博客园 flex2注册码 Flex2.0和C#间的通信[转] - 释天 - 博客园 flash与.net的联合开发(c#,c++)请大家讨论一下 flash中三维动画学习(关于类) flash中一个二维的类 经典言论 c#解答题参考答案 [求教]vs2005下关于css的问题 一个关于文件操作的类(功能还是有点弱) 写了个烂代码,请原谅 C#中接口(interface)的理解 赠送gmail邀请 三个范式的解释 iframe的使用
Gridview的使用
释天 · 2006-09-15 · via 博客园 - 释天

由于初学asp.net2.0,写得不好,请见谅,
由于在写一个文章编辑的页面,使用了gridview这个控件,在itemtemplate里添加了一个linkbutton来
链接到其他页面,但是试了好几种方法,之一使用parent这个属性成功了

代码如下:

 protected void reedit_Click(object sender, EventArgs e)
    
{
        LinkButton lb 
= (LinkButton)sender;  
        DataControlFieldCell df
=(DataControlFieldCell)lb.Parent;
        GridViewRow grv 
= (GridViewRow)df.Parent;
        GridView1.SelectedIndex 
= grv.RowIndex;
        
int tt=grv.RowIndex ;
        
string id;
        id
=GridView1.Rows [tt].Cells [0].Text .ToString ();
        Response.Write(id);
        Message.Text 
= "The primary key value of the selected row is" + GridView1.SelectedDataKey.Values[2];
        Response.Redirect(xxx.aspx?id);
    }

}
 

这样就选取了在gridview的所选列的的数值,(由于我在操作数据库的时候删了一些数据,致使数据的序列不完整,SelectedIndex 获取或设置 GridView 控件中的选中行的索引 ,就不等于在表中的id值了)
同时当我使用selecteddatakey.value.tostring();

 Message.Text = "The primary key value of the selected row is " 
    CustomersGridView.SelectedDataKey.Value.ToString()
 

也可以使用也得到了所选行的数值,

Message.Text = "The primary key value of the selected row is " & _
      CustomersGridView.SelectedValue.ToString() 
& "."

这个只能使用到第一字段,
如果要使用其他字段,就要用到 SelectedDataKey 属性
若要访问第二个键,请将 GridView1.SelectedDataKey[1] 的值用作 DetailsView 控件的 SqlDataSource 控件的 ControlParameter 对象的 PropertyName