在 RowCommand 中获取 GridView 单元格的值 [英] Get value of GridView Cell in RowCommand

查看:22
本文介绍了在 RowCommand 中获取 GridView 单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 RowCommand 事件中获取单元格的值,但该值不在 GridView 的 PrimaryKeyNames 参数中.

I need to get the value of a cell from the RowCommand event, but the value is not in the PrimaryKeyNames parameter of the GridView.

目前我有:

if (e.CommandName == "DeleteBanner")
        {
            GridViewRow row = gvCurrentPubBanner.SelectedRow;
            string BannerName = row.Cells[1].Text;

这不起作用(索引超出范围错误),我也试过:

This doesn't work (index out of range error), I've also tried:

    int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvCurrentBanners.Rows[index];

这也不起作用,因为 CommandArgument(横幅 ID)不是行 ID.

This doesn't work either as the CommandArgument (the banner ID) is not the row ID.

推荐答案

Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)

然后获取密钥或获取单元格并转换为数据控制字段.

Then get the key or get the cell and cast to a datacontrolfield.

Dim id As Guid = GridView1.DataKeys(row.RowIndex).Value

Dim email As String = CType(row.Cells(2), DataControlFieldCell).Text

备注:这只适用于 Boundfields.

Remark: this only works with Boundfields.

这篇关于在 RowCommand 中获取 GridView 单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆