gridview外的button在点击时如何获取gridview某一列的最大值,能否给出具体代码,谢谢

解决方案 »

  1.   

            foreach (GridViewRow row in GridView1.Rows)
            {
                // 用row.Cells[int idx].Text取值,int.Parse转换,再比较。Cells的索引是从0开始的
            }
      

  2.   


            foreach (GridViewRow row in GridView1.Rows) 
            { 
                // 用row.Cells[int idx].Text取值,int.Parse转换,再比较。Cells的索引是从0开始的 
                  // idx就是你要比较的列的编号,编号从0开始 
             } 
      

  3.   

    狂晕,上面的语句可以在button的单击事件里写呀
      

  4.   

    在你的button的click事件里面写:另外比如Gridview里面的一列"charge"为你GridView里面的第3列        int maxcharge = 0;
            foreach (GridViewRow row in GridView1.Rows) 
            { 
                if(maxcharge<Int.Parse(row.cell[2].value))
                {
                   maxcharge = Int.Parse(row.cell[2].value);
                }              
             }
            return maxcharge;//这个最大值就是你要的。 
      

  5.   

           int cellindex = 0;//列序号
           int maxvalue = 0;//初始最大值
            foreach (GridViewRow row in GridView1.Rows)
            {
                text = row.Cells[cellindex].Text;
           }
           string[] check = text.Split(','); //把整个列的值分割成一个字符串
           foreach(string s in check)//对字符串里面的每个值进行比较得出最大值
           {
                s=Int32.Parse(s);
                if(s>maxvalue)
                {
                     maxvalue=s; 
                }
           }
           这样maxvalue就是该列的最大值