得到RowCommand GridView的单元格值 [英] Get value of GridView Cell in RowCommand

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

问题描述

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

目前我有:

 如果(e.CommandName ==DeleteBanner)
        {
            GridViewRow排= gvCurrentPubBanner.SelectedRow;
            字符串BannerName = row.Cells [1]。文本;

这不工作(索引超出范围错误),我也试着:

  INT指数= Convert.ToInt32(e.CommandArgument);
GridViewRow行= gvCurrentBanners.Rows [指数]

这不工作,无论是作为CommandArgument(旗帜ID)不是行ID。


解决方案

 昏暗行作为GridViewRow = CTYPE(CTYPE(e.CommandSource,控制).NamingContainer,GridViewRow)

然后拿到钥匙或获取细胞和铸造到的DataControlField。

 昏暗的ID作为GUID = GridView1.DataKeys(row.RowIndex).value的昏暗的电子邮件作为字符串= CTYPE(row.Cells(2),DataControlFieldCell)。文本

备注:此仅与绑定列

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.

Currently I have:

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];

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

Remark: this only works with Boundfields.

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

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