As many have pointed out the RowDataBound() is the correct event to hook data up for controls within gridview for edit, update or display modes. I was desperate and then tried out Row_Updating. HOwever that wasn't the issue with the error I was getting.
It was mainly due to the Text='<%# Bind("[columnx]")%>'
of,
<asp:DropDownList ID="xnList" runat="server" Text='<%# Bind("[columnx]")%>'>
So the final solution is as per any of the answers posted out there.
cs:
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
DropDownList ddl = e.Row.FindControlRecursive("dhl") as DropDownList;
DropDownList stageDDL = e.Row.FindControlRecursive("dhl") as DropDownList;
stageDDL.DataSource = this.clservice.Getstuff("someparam");
stageDDL.DataTextField = "columnx";
stageDDL.DataValueField = "columnx";
stageDDL.DataBind();
}
}
}
aspx:
<asp:TemplateField HeaderText="x" ItemStyle-CssClass="ix">
<EditItemTemplate>
<asp:DropDownList ID="xnList" runat="server" DataTextField="columnx" DataValueField="columnx">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("[columnx]") %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="ix" />
</asp:TemplateField>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…