我有以下挑戰。我想從後面獲取gridview
上的Items顯示名稱...如何在asp.net中獲取項目值gridview
將此名稱作爲參數傳遞以獲取該項目的響應計數。此響應計數將顯示在創建的模板字段的標籤控件中。
下面是我的代碼示例。
// Create an instance of the LogicLayer
LogicLayer mySurvey = new LogicLayer();
DataLayer getResponseCount = new DataLayer();
protected void Page_Load(object sender, EventArgs e)
{
gvDepartments.DataSource = mySurvey.SelectDepartment();
gvDepartments.DataBind();
gvDepartments.Visible = true;
// Declare a counter variable
int dID = 0;
string responses;
string deptName;
//string responseR;
// Iterate though the gridView to get Dept names and response count values
foreach (GridViewRow dept in gvDepartments.Rows)
{
//Label respCount = (Label)dept.FindControl("lblResponse").Text
// the actual way to get your row index
int rowIndex = dept.RowIndex;
Label respCount = (Label)gvDepartments.Rows[rowIndex].FindControl("lblResponses");
responses = respCount.Text.ToString();
deptName = dept.Cells[rowIndex].ToString(); // Get the department name on the gridview
// get the responseCount for each of the departments and Map to Labels
responses = getResponseCount.ResponseCount(deptName);
dID++;
}
}
這是我的網格的圖像視圖。
可能更好地'mySurvey.SelectDepartment計算'respCount'()',而不是從電網 – Grundy
你肯定不明白我的問題。方法mySurvey.SelectDepartment()返回一個綁定到GridView的DataSet。我需要有界部門的名字才能得到該部門的答覆。 – Guzzyman