I have the following challenge. I want to get the name of the Items display on the gridview from the side behind...
Pass this name as a parameter to get the count of responses for the item. This response count will be displayed on a label controls in the template fields created.
Below is my code sample.
// 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++;
}
}
This is the pictural view of my grid.

respCountfrommySurvey.SelectDepartment()instead of from grid