I am trying to bind dropdownlist in Gridview under EditItemTemplate under RowBound event. But it gives me blank rows in the drop down list:
Here is my Design
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>' Width="400px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlNewDesc" runat="server" Width="400px" ></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlNewDescFooter" runat="server" Width="400px">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
Here is code behind:
protected void grdFerries_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Edit)
{
DropDownList ddlNewDesc = (DropDownList)e.Row.FindControl("ddlNewDesc");
DataAccessClass DAC = new DataAccessClass();
string Query = "select description from JoursFeries where Year(JoursFeries.date) >= Year(GETDATE()) order by date asc";
DataTable dtddl = DAC.ReturnDatatablefromQuery(Query, DBConnectionString);
ddlNewDesc.DataSource = dtddl;
ddlNewDesc.DataTextField = "description";
ddlNewDesc.DataValueField = "description";
ddlNewDesc.DataBind();
}
}
}
I see the dropdown but the dropdown is blank, but there are rows in the database for this column and in the footer row it is working fine.
Pls help.