Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Binding a usercontrol in a gridview
Message
De
23/08/2014 06:01:28
 
 
À
22/08/2014 12:55:22
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01606284
Message ID:
01606297
Vues:
37
>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)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform