W
william.oram
I have a DataGrid and a column that changes into a DropDownList when
edited:
<columns>
<asp:templatecolumn headertext="Role Type">
<itemtemplate>
<asp:hyperlink id="hlinkRoleType" navigateurl='<%#
"contact_roles_details.aspx?id=" + DataBinder.Eval(Container,
"DataItem.ID", "{0}").ToString() %>' Text='<%#
DataBinder.Eval(Container, "DataItem.Role", "{0}").ToString() %>'
runat="server"/>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="ddlRoleEdit"
datavaluefield="ID" datatextfield="Name" datasource="<%#
FillRoleList() %>" ondatabinding="ddlRoleEdit_ItemDataBound"
runat="server" />
</edititemtemplate>
</asp:templatecolumn>
<asp:editcommandcolumn buttontype="LinkButton"
edittext="<img src="images/edit_icon.gif">" />
<asp:buttoncolumn text="<img src="images/delete_icon.gif">"
commandname="deleteRole"></asp:buttoncolumn>
</columns>
I've spent many many hours trying to set the default value of the DDL
to whatever was present before editing. Everything I've inserted into
the *** below stirs up some petty technical error in C#:
public void ddlRoleEdit_ItemDataBound(Object sender,
DataGridItemEventArgs e)
{
DropDownList ddl = (DropDownList) sender;
ddl.SelectedValue = ***
}
edited:
<columns>
<asp:templatecolumn headertext="Role Type">
<itemtemplate>
<asp:hyperlink id="hlinkRoleType" navigateurl='<%#
"contact_roles_details.aspx?id=" + DataBinder.Eval(Container,
"DataItem.ID", "{0}").ToString() %>' Text='<%#
DataBinder.Eval(Container, "DataItem.Role", "{0}").ToString() %>'
runat="server"/>
</itemtemplate>
<edititemtemplate>
<asp:dropdownlist id="ddlRoleEdit"
datavaluefield="ID" datatextfield="Name" datasource="<%#
FillRoleList() %>" ondatabinding="ddlRoleEdit_ItemDataBound"
runat="server" />
</edititemtemplate>
</asp:templatecolumn>
<asp:editcommandcolumn buttontype="LinkButton"
edittext="<img src="images/edit_icon.gif">" />
<asp:buttoncolumn text="<img src="images/delete_icon.gif">"
commandname="deleteRole"></asp:buttoncolumn>
</columns>
I've spent many many hours trying to set the default value of the DDL
to whatever was present before editing. Everything I've inserted into
the *** below stirs up some petty technical error in C#:
public void ddlRoleEdit_ItemDataBound(Object sender,
DataGridItemEventArgs e)
{
DropDownList ddl = (DropDownList) sender;
ddl.SelectedValue = ***
}