G
George Durzi
Inside <columns/> in my datagrid, I have the following template column
<asp:templatecolumn HeaderText="To Be Completed By">
<itemtemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.FULL_NAME") %>'><asp:label>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist ID="cboToBeCompletedBy"
Runat="server"></asp:dropdownlist>
</edititemtemplate>
<asp:templatecolumn>
this template column is in cell 2 (0,1,2)
In my EditCommand event, I'd like to populate this dropdownlist. I call this
code
dgStatusIncomplete.EditItemIndex = e.Item.ItemIndex;
FetchSurveyStatusIncomplete(); // Populates the DataGrid
FetchUsersbyDepartment(
e.Item.Cells[2].FindControl("cboToBeCompletedBy"),
e.Item.Cells[3].Text.ToString());
The problem is that e.Item.Cells[2].FindControl("cboToBeCompletedBy") is
returning null, so the FetchUsersbyDepartment isn't receiving the drop down
list control as a parameter, it is incorrectly receiving null as a
parameter. Any idea?
private void FetchUsersbyDepartment(object control, string DeptId)
{
// Fetch Users for the Department
DataSet dsStaff = Department.FetchUsersbyDepartment(ConnectString,
DeptId);
System.Web.UI.WebControls.DropDownList ctrl =
(System.Web.UI.WebControls.DropDownList)control;
using (dsStaff)
{
if (dsStaff.Tables[0].Rows.Count > 0)
{
ctrl.DataSource = dsStaff;
ctrl.DataTextField = "USER_NAME";
ctrl.DataValueField = "ID";
ctrl.DataBind();
}
}
}
<asp:templatecolumn HeaderText="To Be Completed By">
<itemtemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.FULL_NAME") %>'><asp:label>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist ID="cboToBeCompletedBy"
Runat="server"></asp:dropdownlist>
</edititemtemplate>
<asp:templatecolumn>
this template column is in cell 2 (0,1,2)
In my EditCommand event, I'd like to populate this dropdownlist. I call this
code
dgStatusIncomplete.EditItemIndex = e.Item.ItemIndex;
FetchSurveyStatusIncomplete(); // Populates the DataGrid
FetchUsersbyDepartment(
e.Item.Cells[2].FindControl("cboToBeCompletedBy"),
e.Item.Cells[3].Text.ToString());
The problem is that e.Item.Cells[2].FindControl("cboToBeCompletedBy") is
returning null, so the FetchUsersbyDepartment isn't receiving the drop down
list control as a parameter, it is incorrectly receiving null as a
parameter. Any idea?
private void FetchUsersbyDepartment(object control, string DeptId)
{
// Fetch Users for the Department
DataSet dsStaff = Department.FetchUsersbyDepartment(ConnectString,
DeptId);
System.Web.UI.WebControls.DropDownList ctrl =
(System.Web.UI.WebControls.DropDownList)control;
using (dsStaff)
{
if (dsStaff.Tables[0].Rows.Count > 0)
{
ctrl.DataSource = dsStaff;
ctrl.DataTextField = "USER_NAME";
ctrl.DataValueField = "ID";
ctrl.DataBind();
}
}
}