如何总结与时间格式(00:00:00)行并在网格视图页脚生产? [英] How to sum of rows with time format(00:00:00) and produce in footer of Grid View?
问题描述
由于是在.net初学者,很困惑我的问题之一。
的事情是,我有一列中的内容为8:7:15,9:15:12和10:3:4。
我的问题是,如何添加这三行,并在网格视图为27:25:31的页脚生产。我知道,以行之和,但我仍坚持这一类型的格式。
任何帮助将是对我更有帮助。
先谢谢了。
我将三个列值回你的SQL查询和值赋值的字符串,现在,我们可以计算出你的要求值,见下文
字符串X1 =8:7:15; //第一列值
字符串X2 =9点15分十二秒; // 2ndcolumn值
串X3 =10:3:4; //第3列的值
字符串[] = CX1 x1.Split(':');
字符串[] = CX2 x2.Split(':');
字符串[] = CX3 x3.Split(':');
串的Tx1 =((Convert.ToInt32(CX1 [0])+ Convert.ToInt32(CX2 [0])+ Convert.ToInt32(CX3 [0]))+:+(Convert.ToInt32(CX1 [1])
+ Convert.ToInt32(CX2 [1])+ Convert.ToInt32(CX3 [1])))+:+(Convert.ToInt32(CX1 [2])+ Convert.ToInt32(CX2 [2])+转换。 。ToInt32(CX3 [2]))的ToString();
最后,你可以把这个值的Tx1到您的页脚单元格。
块引用>更新
字符串X1 =8:7:15; //第一列值
字符串X2 =9点15分十二秒; // 2ndcolumn值
串X3 =10:3:4; //第3列的值
串×4 =1:1:1;
串X5 =1:1:1; //我刚刚分配5个值,但是你可以在该数组中分配比很多更值
字符串[] = XXA新的字符串[5];
XXA [0] = X 1;
XXA [1] = X 2;
XXA [2] = X 3;
XXA [3] = 4倍;
XXA [4] = X5;
串Tvalue1 =0;
串Tvalue2 =0;
串Tvalue3 =0;
//现在XXA有5行(有多少行没有问题),因此,这会的foreach第5轮时间 的for(int i = 0; I< GridView1.Rows.Count;我++)//现在xxA.Length 5
{
字符串x = GridView1.Rows [I] .Cells [9]的ToString();
INT N = GridView1.Rows.Count;
字符串[] = XXA新的字符串[N];
XXA [I] = X;
//下面是一些逻辑对计算和格式化
字符串[] = CX1 XXA [I] .Split(':');
Tvalue1 =(Convert.ToInt32(Tvalue1)+ Convert.ToInt32(CX1 [0]))的ToString();
Tvalue2 =(Convert.ToInt32(Tvalue2)+ Convert.ToInt32(CX1 [1]))的ToString();
Tvalue3 =(Convert.ToInt32(Tvalue3)+ Convert.ToInt32(CX1 [2]))的ToString();
}
串FInalValue = Tvalue1 +:+ Tvalue2 +:+ Tvalue3;现在你可以在FInalValue变量的总格式化值。
最后code
字符串Tvalue1 =0;
串Tvalue2 =0;
串Tvalue3 =0;
的for(int i = 0;我3;;我++)//这里3 gridview的行长度
{
字符串x =1:1:1; //这是你的单元格值
INT N = 3;
字符串[] = XXA新的字符串[N];
XXA [I] = X;
//下面是一些逻辑对计算和格式化
字符串[] = CX1 XXA [I] .Split(':');
Tvalue1 =(Convert.ToInt32(Tvalue1)+ Convert.ToInt32(CX1 [0]))的ToString();
Tvalue2 =(Convert.ToInt32(Tvalue2)+ Convert.ToInt32(CX1 [1]))的ToString();
Tvalue3 =(Convert.ToInt32(Tvalue3)+ Convert.ToInt32(CX1 [2]))的ToString();
}
串FInalValue = Tvalue1 +:+ Tvalue2 +:+ Tvalue3;请参阅此演示:
As am a beginner in .Net, am confusing with one of my question.
The thing is, am having a content in one column as 8:7:15, 9:15:12,and 10:3:4.
My question is, How to add these three rows and produce in footer of Grid view as 27:25:31. I know to make of sum of rows but am stuck with this type of format.Any help would be more helpful to me.
Thanks in advance.解决方案I assign three column value return your sql query and that values are assigned three string , Now we can calculate that values for your requirement , see below
string x1 = "8:7:15";//1st column value string x2 = "9:15:12";//2ndcolumn value string x3 = "10:3:4";//3rd column value string[] Cx1 = x1.Split(':'); string[] Cx2 = x2.Split(':'); string[] Cx3 = x3.Split(':'); string Tx1 = ((Convert.ToInt32(Cx1[0]) + Convert.ToInt32(Cx2[0]) + Convert.ToInt32(Cx3[0])) + ":" + (Convert.ToInt32(Cx1[1]) + Convert.ToInt32(Cx2[1]) + Convert.ToInt32(Cx3[1]))) + ":" + (Convert.ToInt32(Cx1[2]) + Convert.ToInt32(Cx2[2]) + Convert.ToInt32(Cx3[2])).ToString();
Finally you can give this Tx1 value to your footer cell .
Update
string x1 = "8:7:15";//1st column value string x2 = "9:15:12";//2ndcolumn value string x3 = "10:3:4";//3rd column value string x4 = "1:1:1"; string x5 = "1:1:1"; // , I just assign 5 values,but you can assign more than lot values in this array string[] xxA = new string[5]; xxA[0] = x1; xxA[1] = x2; xxA[2] = x3; xxA[3] = x4; xxA[4] = x5; string Tvalue1 = "0"; string Tvalue2 = "0"; string Tvalue3 = "0"; //Now the xxA has 5 rows (No problem for how many rows ) So this foreach will round 5 time for(int i = 0; i < GridView1.Rows.Count; i++)//Now xxA.Length is 5 { string x = GridView1.Rows[i].Cells[9].ToString(); int n=GridView1.Rows.Count; string[] xxA=new string[n]; xxA[i] = x; //Here is the some logic's for the calculation and formating string[] Cx1 = xxA[i].Split(':'); Tvalue1 = (Convert.ToInt32(Tvalue1) + Convert.ToInt32(Cx1[0])).ToString() ; Tvalue2 = (Convert.ToInt32(Tvalue2) + Convert.ToInt32(Cx1[1])).ToString() ; Tvalue3 = (Convert.ToInt32(Tvalue3) + Convert.ToInt32(Cx1[2])).ToString(); } string FInalValue = Tvalue1 +":"+ Tvalue2 + ":"+ Tvalue3;
Now you can get the total formating values in FInalValue variable.
Final code:
string Tvalue1 = "0"; string Tvalue2 = "0"; string Tvalue3 = "0"; for (int i = 0; i < 3; i++)//here 3 is gridview row length { string x = "1:1:1";//This your cell value int n = 3; string[] xxA = new string[n]; xxA[i] = x; //Here is the some logic's for the calculation and formating string[] Cx1 = xxA[i].Split(':'); Tvalue1 = (Convert.ToInt32(Tvalue1) + Convert.ToInt32(Cx1[0])).ToString(); Tvalue2 = (Convert.ToInt32(Tvalue2) + Convert.ToInt32(Cx1[1])).ToString(); Tvalue3 = (Convert.ToInt32(Tvalue3) + Convert.ToInt32(Cx1[2])).ToString(); } string FInalValue = Tvalue1 + ":" + Tvalue2 + ":" + Tvalue3;
See this Demo :
这篇关于如何总结与时间格式(00:00:00)行并在网格视图页脚生产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!