gpt4 book ai didi

c# - 在 RowCommand 中获取 GridView Cell 的值

转载 作者:太空狗 更新时间:2023-10-29 17:35:07 24 4
gpt4 key购买 nike

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

目前我有:

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

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

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

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

最佳答案

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

然后获取 key 或获取单元格并转换为数据控制字段。

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

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

注意:这只适用于 Boundfields。

关于c# - 在 RowCommand 中获取 GridView Cell 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10783962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com