ASP.NET系列之点滴积累(一):GridView中获取选定行中数据
来源:互联网 发布:SQL存入新表 编辑:程序博客网 时间:2024/05/21 06:41
上次做一个网站的时候,遇到一个问题: 在绑定了数据的GridView 中,我需要把选定的行中数据读取出来保存到一个结构体中以便将这些数据传递到下一个页面,问了一些朋友,找的些资料,最终没有结果,一个朋友说可以把数据行的ID传递到下一个页面时再进行绑定,当时一想,这办法可以,但当我去做的时候才知道当我得到上面页面传递的ID后还需要进行绑定太麻烦了,我相信通过结构体的方式传递到下页更方便,所以我一直在找方法,今天早上才发现,获取某行数据并不难:
首先添加一模版列用来选定或者获取当前选中行的行号,然后通过GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;这样的方式获取想要的数据单元。只需把没个单元数据保存为一个结构体即可。
注意的是,我在设置模版列时把GridView的CommandName属性设置为select(这是默认值),这样才能获取行号。
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
...{
ProviderDetail pdetail = new ProviderDetail();
pdetail.sGameName = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
pdetail.sAreaName = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
pdetail.sServerName = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
pdetail.nMaxNum = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
pdetail.sPrice = GridView1.Rows[e.NewSelectedIndex].Cells[4].Text;
pdetail.sMinDeal = GridView1.Rows[e.NewSelectedIndex].Cells[5].Text;
Session["PD"] = pdetail;
Response.Redirect("~/ProviderDetails.aspx");
}
...{
ProviderDetail pdetail = new ProviderDetail();
pdetail.sGameName = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
pdetail.sAreaName = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
pdetail.sServerName = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
pdetail.nMaxNum = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
pdetail.sPrice = GridView1.Rows[e.NewSelectedIndex].Cells[4].Text;
pdetail.sMinDeal = GridView1.Rows[e.NewSelectedIndex].Cells[5].Text;
Session["PD"] = pdetail;
Response.Redirect("~/ProviderDetails.aspx");
}
- ASP.NET系列之点滴积累(一):GridView中获取选定行中数据
- asp.net中GridView内部点击事件判断是第几行并获取row数据
- asp.net gridview itemtemplate中控件事件获取行参数
- 菜鸟学Asp.Net——GridView控件之RowDataBind事件中如何获取已绑定的数据
- asp.net中gridview数据相同行的列合并
- asp.net 中Gridview
- .net之gridview表中数据操作
- ASP.NET中GridView中嵌套GridView
- Asp.net之获取GridView控件中TextBox等控件的值
- ASP.NET中GridView多行操作
- ASP.NET中gridview获取当前行的索引值
- asp.net 获取Gridview隐藏列的值 整理中
- asp.net中获取GridView当前行的索引
- asp.net 获取GridView中a标签并进行操作
- Scott Mitchell 的ASP.NET 2.0数据教程之十二:在GridView控件中使用TemplateField
- Scott Mitchell 的ASP.NET 2.0数据教程之十二:在GridView控件中使用TemplateField
- Scott Mitchell 的ASP.NET 2.0数据教程之十二:在GridView控件中使用TemplateField
- asp.net技巧点滴(一):在asp.net中使用客户端脚本
- JavaMail使用教程
- JVM tuning
- 分享MySQL和php採用UTF8的详细方法
- ASP.NET技术规范
- asp.net中WebUserControl的使用小技巧
- ASP.NET系列之点滴积累(一):GridView中获取选定行中数据
- UNo-API的数据类型
- MS06-014原始代码
- Position Paper For the Workshop on Web of Services for Enterprise Computing
- 通过样式表实现固定表头和列
- java里的一些经典问题
- my body
- 鼠标编程(简单版)
- GUID