Hi Guys,
I have a dropdownlist that controls the contents of 3 gridview controls. These are used in a webpart. However, every time the selectedindexchanged method of the dropdownlist fires an event, the contents of the dependent gridviews adds another rendering of a gridview. Hence, it doubles and even triples the contents of those gridviews.
I have the following codes:
->for the CreatChildControls method:
ProfileGrid(_gridProf, _dtProf, _infoObj, _column, _imgColumn, _ddl, _strConn, _id);
Controls.Add(_gridProf);
Controls.Add(new LiteralControl("<br />"));
PhysicalGrid(_gridPhys, _dtPhys, _infoObj, _column, _ddl, _strConn, _id);
Controls.Add(_gridPhys);
Controls.Add(new LiteralControl("<br />"));
LabGrid(_gridLab, _dtLab, _infoObj, _column, _ddl, _strConn, _id);
Controls.Add(_gridLab);
Controls.Add(new LiteralControl("<br />"));
->for the SelectedIndexChanged method:
private void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
ProfileGrid(_gridProf, _dtProf, _infoObj, _column, _imgColumn, _ddl, _strConn, _id);
PhysicalGrid(_gridPhys, _dtPhys, _infoObj, _column, _ddl, _strConn, _id);
LabGrid(_gridLab, _dtLab, _infoObj, _column, _ddl, _strConn, _id);
}
->for one of the GridView Controls:
private void ProfileGrid(GridView grid, DataTable dt, InfoAccess infoObj, BoundField column, ImageField imgColumn, DropDownList ddl, string strConn, string id)
{
string query = "exec spr_VITALITY_SCORE '" + id + "', '" + (ddl.SelectedValue == "" ? DateTime.Now.Year.ToString() : ddl.SelectedValue.ToString()) + "'";
infoObj.StrConn = strConn;
dt = infoObj.SQLResult(query);
grid.DataSource = dt;
column.DataField = "SCORE";
column.HeaderText = "Score";
grid.Columns.Add(column);
imgColumn.DataImageUrlField = "VITALITY_COLOR";
imgColumn.DataImageUrlFormatString = "../../Style%20Library/OHImages/{0}";
imgColumn.HeaderText = "Vitality Color";
grid.Columns.Add(imgColumn);
column = new BoundField();
column.DataField = "VITALITY_DEFINITION";
column.HeaderText = "Vitality Definition";
grid.Columns.Add(column);
column = new BoundField();
column.DataField = "REMARKS";
column.HeaderText = "Remarks";
grid.Columns.Add(column);
DesignGrid(_gridProf);
_gridProf.Attributes.Add("Style", "text-align:center;");
}
The DesignGrid method only defines the attributes of the gridviews. Can anyone please assist me on this incorrect rendering problem? Thanks.