在gridview中搜索值 [英] searching the value in gridview

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

问题描述

嗨 如何在gridview中搜索数值.

 公共  void  sa(GridView gv1)
{
     int  c1 =  0 ;
     int  cv1 =  0 ;
     int 答案;
     foreach (GridViewRow行 in  gv1.Rows中的行)
    {
        cv1 = System.Convert.ToInt32(row.Cells [ 4 ].Text);
        c1 + = currentValue1;
    }
    ans = c1;
        随机RandomClass =  Random();
         int  RandomNumber = RandomClass.Next( 1 ,ans);
        Response.Write(RandomNumber);
         foreach (GridViewRow r  in  gv1.Rows中)
        {
            gv1.FindControl(ans.ToString());
        }
} 

解决方案

嗨Gowdhami,

在计算cf的循环中,将cf作为键存储,将行索引存储为字典中的值.之后,一旦生成了随机数,请检查字典是否与任何cf ..相匹配(只需使用contains(key)方法进行匹配).如果随机数存在,您将获得行索引.使用结果行索引,您可以从gridview中获取该行,然后从所需的单元格或其中的值中获取该行.

这有帮助吗?

注意:cf集合中的随机数可能不完全匹配.相反,您想查找最接近的值吗?.


hi how to search the numeric value in gridview.

public void sa(GridView gv1)
{
    int c1 = 0;
    int cv1 = 0;
    int ans;
    foreach (GridViewRow row in gv1.Rows)
    {
        cv1 = System.Convert.ToInt32(row.Cells[4].Text);
        c1 += currentValue1;
    }
    ans = c1;
        Random RandomClass = new Random();
        int RandomNumber = RandomClass.Next(1, ans);
        Response.Write(RandomNumber);
        foreach (GridViewRow r in gv1.Rows)
        {
            gv1.FindControl(ans.ToString());
        }
}

解决方案

Hi Gowdhami,

In your loop calculating the cf, store the cf as key and row index as value in a dictionary. Later once the random number generated check the dictionary whether the random number matches with any cf..(just use the contains(key) method to match). If the random number exists you will get the row index. Using the result row index you can get the row from the gridview then the desire cell or the value in it.

Does this help?

Note: Random number may not exactly match in the cf collection. Instead you want to find the nearest value?.


这篇关于在gridview中搜索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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