[英]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.