获取的GridView行通过的DataKeyNames [英] Getting Gridview Row By Datakeynames

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

问题描述

我有一个gridview,它有的DataKeyNames =ID

I have a gridview and it has datakeynames="Id"

我有一个标识在code文件。现在,我希望得到一个特定ID的行。

I have that Id in code file. Now I want to get the row of a specific Id.

例如ID = 1然后我希望得到一个具有ID = 1的GridView的行
我用这个code:

For example Id=1 then I want to get the row of gridview that has Id=1 I've used this code:

foreach (DataKey key in gdvMainList.DataKeys)
                {
                    if (Convert.ToInt32(key.Value) == consentReleaseId)
                    {
                        gdvMainListRow = gdvMainList.Rows[index];
                        break;
                    }
                    index++;
                }

有没有什么更好的办法?

Is there any better approach?

推荐答案

另一种办法是通过在GridView的项目循环,直到找到匹配的密钥。

Another option would be loop through the items in the GridView until you find the matching key.

foreach (GridViewRow row in GridView1.Rows)
{
    if (GridView1.DataKeys[row.RowIndex]["ID"] == consentReleaseId)
    {
        gdvMainListRow = row;
        break;
    }
}

这篇关于获取的GridView行通过的DataKeyNames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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