>Hi All -
>
>I thought I would save myself some time by creating a usercontrol for a commonly used dropdownlist, but it seems like it may be more trouble than its worth. The UC consists simply of a DDL, a SQLdatasource, and a required field validator. I can manage to use it OK when it is placed directly on a form and doesn't need to be bound to any existing data. However I also need to use it inside the edit template of a gridview. In this case I can't figure out how to bind it to the current selected value in the row. The gridview is populated via code behind. I am about ready to abandon this idea unless someone here can illustrate how this is done. (I posted on the MS Forums but so far have not received an answer.)
>
>Thanks
I think it's fairly simple.
(a) Expose the SelectedValue of the DropDownList in your UserControl:
[Bindable(true)]
public string SelectedValue
{
get { return DropDownList1.SelectedValue; }
set { DropDownList1.SelectedValue = value; }
}
(b) Add a Template field to the GridView.Columns that binds the value:
{asp:TemplateField}
{EditItemTemplate}
{uc1:WebUserControl ID="WebUserControl1" runat="server" SelectedValue='{%# Bind("TargetField") %}' /}
{/EditItemTemplate}
{/asp:TemplateField}
(UT choked on the markup so I've substituted curly braces for angle brackets)