SelectedIndex Within EditCommandColumn

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 = ***
}
 
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 = ***
}

Revision: I swear 'public void ddlRoleEdit_ItemDataBound(Object
sender,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top