如何比较gridview控件中两个下拉列表的值 [英] How to compare values of two drop downl list in gridview control

查看:76
本文介绍了如何比较gridview控件中两个下拉列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,其中每行都有一个下拉列表。我坚持一点,我必须将这些下拉列表的值相互比较。如果相同的值仍然存在,那么它将显示错误消息,否则它将继续。



提前感谢。

I have a gridview in which at each row there is a dropdown list. I stuck to a point that I have to compare the values of these dropdown with each other. If the same value persist, then it will show error message otherwise it will continue.

Thanks in advance.

推荐答案

Hello Vijay,你必须循环遍历GridView控件中的所有行,并比较是否有任何重复值。请尝试以下代码:

Hello Vijay, you have to loop through all the rows in your GridView control and compare if there is any duplicate value. Try the following code:
bool foundDuplicate = false;
for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
    DropDownList ddl1 = (DropDownList)GridView1.Rows[i].FindControl("ddlName");
    for (int j = i + 1; j < GridView1.Rows.Count; j++)
    {
        DropDownList ddl2 = (DropDownList)GridView1.Rows[j].FindControl("ddlName");

        if (ddl1.SelectedValue == ddl2.SelectedValue)
        {
            foundDuplicate = true;
            break;
        }
    }

    if (foundDuplicate == true)
    {
        break;
    }
}



如果您有任何进一步的询问,请告诉我。



- DD


Let me know if you have any further query.

- DD


嗨Vijay,你为什么试过?如何在业务逻辑中进行比较?



问候。
Hi Vijay, Why did you tried? How about compare in the Business Logic?

Regards.


这篇关于如何比较gridview控件中两个下拉列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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