[英]How can I get the row selected in my gridview to display in my text boxes?
[英]How can I get the total number of certain text in my `GridView` and display in a label?
我想在我的 web 应用程序中的 label 中的一列中显示某些文本的总数所以在我的GridView
中,我有一个包含两个文本的列。 一个是E1,另一个是E3。 现在我想做的是有两个标签显示 E1 的总数,第二个 label 显示 E3 的总数。
所以如果这是我的专栏:
| Type |
| E1 |
| E3 |
| E3 |
| E1 |
| E1 |
与此类似的东西
Total E1 = 3
Total E3 = 2
我不知道如何实现这一点,所以希望有人能指出我正确的方向?
谢谢
你可以尝试这样的事情。 只需计算值是您想要的数据的单元格,例如字符串:
int iCount = 0;
for (int i = 0; i < GridView.RowCount-1; i++)
{
for (int j = 1; j < GridView.ColumnCount - 1; j++)
{
if (GridView[j, i].Value.ToString() == "E1")
iCount++;
}
}
你可以试试这个:
int CountItem1 = 0;
int CountItem2 = 0;
int ColumnNumber = 2; //This is the column you want to verify. Starts from 0 to GridViewOffice365.ColumnNumbers -1
for each (GridViewRow row in GridViewOffice365.Rows)
{
if (row.Cells[ColumnNumber].Text == "E1")
{
CountItem1++;
}
else if (row.Cells[ColumnNumber].Text == "E3")
{
CountItem2++;
}
}
lblE1.Text = "Total E1: " CountItem1.ToString();
lblE3.Text = "Total E3: " + CountItem2.ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.