Creating a reusable dropdownlist for use in formview

Discussion in 'ASP .Net Building Controls' started by Rodrigo Juarez, Feb 25, 2006.

  1. Hi

    I need to create a dropdownlist for reusing in a lot of formviews, with
    databinding.

    If I create a user control the selectedvalue is not usable for databinding
    in formview.

    Thanks in advance
     
    Rodrigo Juarez, Feb 25, 2006
    #1
    1. Advertising

  2. Rodrigo Juarez

    Teemu Keiski Guest

    Hi,

    if you create a User Control, you can expose the SelectedValue and other
    properties of the DroPDownList from the user control. You can for example
    just create another property on the UC. Assuming you already have a
    DropDownList with ID "DropDownList1" in the user control, you could have a
    property as follows:

    public string DdlSelectedValue
    {
    get
    {
    return DropDownList1.SelectedValue;
    }
    set
    {
    DropDownList1.SelectedValue = value;
    }
    }

    to expose the DDL's SelectedValue.

    If you need more from the DDL, you can expose more properties or even the
    DropDOwnList itself entirely with a read-only property.


    public DropDownList InnerDDL
    {
    get
    {
    return DropDownList1;
    }
    }


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    "Rodrigo Juarez" <> wrote in message
    news:...
    > Hi
    >
    > I need to create a dropdownlist for reusing in a lot of formviews, with
    > databinding.
    >
    > If I create a user control the selectedvalue is not usable for databinding
    > in formview.
    >
    > Thanks in advance
    >
    >
     
    Teemu Keiski, Feb 26, 2006
    #2
    1. Advertising

  3. Thanks for your reply.

    Here is the content of ascx file for my user control

    <%@ Control Language="VB" AutoEventWireup="false"
    CodeFile="tipocuenta.ascx.vb" Inherits="tipocuenta" %>

    <script runat="server">

    Public Property TipoCuentaSel() As String

    Get

    Return ddlTipoCuenta.SelectedValue

    End Get

    Set(ByVal value As String)

    ddlTipoCuenta.SelectedValue = value

    End Set

    End Property

    </script>

    <asp:DropDownList ID="ddlTipoCuenta" runat="server">

    <asp:ListItem Value="2">Cuenta Corriente</asp:ListItem>

    <asp:ListItem Value="3">Caja de Ahorro</asp:ListItem>

    </asp:DropDownList>



    I'm using the control in the insert template in a form view, but the
    property TipoCuentaSel() is not available for databinding ...

    What can I do?

    TIA

    Rodrigo Juarez



    "Teemu Keiski" <> escribió en el mensaje
    news:...
    > Hi,
    >
    > if you create a User Control, you can expose the SelectedValue and other
    > properties of the DroPDownList from the user control. You can for example
    > just create another property on the UC. Assuming you already have a
    > DropDownList with ID "DropDownList1" in the user control, you could have a
    > property as follows:
    >
    > public string DdlSelectedValue
    > {
    > get
    > {
    > return DropDownList1.SelectedValue;
    > }
    > set
    > {
    > DropDownList1.SelectedValue = value;
    > }
    > }
    >
    > to expose the DDL's SelectedValue.
    >
    > If you need more from the DDL, you can expose more properties or even the
    > DropDOwnList itself entirely with a read-only property.
    >
    >
    > public DropDownList InnerDDL
    > {
    > get
    > {
    > return DropDownList1;
    > }
    > }
    >
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    >
    > "Rodrigo Juarez" <> wrote in message
    > news:...
    > > Hi
    > >
    > > I need to create a dropdownlist for reusing in a lot of formviews, with
    > > databinding.
    > >
    > > If I create a user control the selectedvalue is not usable for

    databinding
    > > in formview.
    > >
    > > Thanks in advance
    > >
    > >

    >
    >
     
    Rodrigo Juarez, Feb 27, 2006
    #3
  4. Rodrigo Juarez

    Teemu Keiski Guest

    Hi,

    post also the FormView code. Do you get any specific error msg?`

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    "Rodrigo Juarez" <> wrote in message
    news:e$...
    > Thanks for your reply.
    >
    > Here is the content of ascx file for my user control
    >
    > <%@ Control Language="VB" AutoEventWireup="false"
    > CodeFile="tipocuenta.ascx.vb" Inherits="tipocuenta" %>
    >
    > <script runat="server">
    >
    > Public Property TipoCuentaSel() As String
    >
    > Get
    >
    > Return ddlTipoCuenta.SelectedValue
    >
    > End Get
    >
    > Set(ByVal value As String)
    >
    > ddlTipoCuenta.SelectedValue = value
    >
    > End Set
    >
    > End Property
    >
    > </script>
    >
    > <asp:DropDownList ID="ddlTipoCuenta" runat="server">
    >
    > <asp:ListItem Value="2">Cuenta Corriente</asp:ListItem>
    >
    > <asp:ListItem Value="3">Caja de Ahorro</asp:ListItem>
    >
    > </asp:DropDownList>
    >
    >
    >
    > I'm using the control in the insert template in a form view, but the
    > property TipoCuentaSel() is not available for databinding ...
    >
    > What can I do?
    >
    > TIA
    >
    > Rodrigo Juarez
    >
    >
    >
    > "Teemu Keiski" <> escribió en el mensaje
    > news:...
    >> Hi,
    >>
    >> if you create a User Control, you can expose the SelectedValue and other
    >> properties of the DroPDownList from the user control. You can for example
    >> just create another property on the UC. Assuming you already have a
    >> DropDownList with ID "DropDownList1" in the user control, you could have
    >> a
    >> property as follows:
    >>
    >> public string DdlSelectedValue
    >> {
    >> get
    >> {
    >> return DropDownList1.SelectedValue;
    >> }
    >> set
    >> {
    >> DropDownList1.SelectedValue = value;
    >> }
    >> }
    >>
    >> to expose the DDL's SelectedValue.
    >>
    >> If you need more from the DDL, you can expose more properties or even the
    >> DropDOwnList itself entirely with a read-only property.
    >>
    >>
    >> public DropDownList InnerDDL
    >> {
    >> get
    >> {
    >> return DropDownList1;
    >> }
    >> }
    >>
    >>
    >> --
    >> Teemu Keiski
    >> ASP.NET MVP, AspInsider
    >> Finland, EU
    >> http://blogs.aspadvice.com/joteke
    >>
    >>
    >> "Rodrigo Juarez" <> wrote in message
    >> news:...
    >> > Hi
    >> >
    >> > I need to create a dropdownlist for reusing in a lot of formviews, with
    >> > databinding.
    >> >
    >> > If I create a user control the selectedvalue is not usable for

    > databinding
    >> > in formview.
    >> >
    >> > Thanks in advance
    >> >
    >> >

    >>
    >>

    >
    >
    >
     
    Teemu Keiski, Feb 27, 2006
    #4
  5. No erro, the problem is I can't bind data with smart tag options, but I code
    the control and works fine.
    Thanks for your help

    "Teemu Keiski" <> escribió en el mensaje
    news:...
    > Hi,
    >
    > post also the FormView code. Do you get any specific error msg?`
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    > "Rodrigo Juarez" <> wrote in message
    > news:e$...
    > > Thanks for your reply.
    > >
    > > Here is the content of ascx file for my user control
    > >
    > > <%@ Control Language="VB" AutoEventWireup="false"
    > > CodeFile="tipocuenta.ascx.vb" Inherits="tipocuenta" %>
    > >
    > > <script runat="server">
    > >
    > > Public Property TipoCuentaSel() As String
    > >
    > > Get
    > >
    > > Return ddlTipoCuenta.SelectedValue
    > >
    > > End Get
    > >
    > > Set(ByVal value As String)
    > >
    > > ddlTipoCuenta.SelectedValue = value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > </script>
    > >
    > > <asp:DropDownList ID="ddlTipoCuenta" runat="server">
    > >
    > > <asp:ListItem Value="2">Cuenta Corriente</asp:ListItem>
    > >
    > > <asp:ListItem Value="3">Caja de Ahorro</asp:ListItem>
    > >
    > > </asp:DropDownList>
    > >
    > >
    > >
    > > I'm using the control in the insert template in a form view, but the
    > > property TipoCuentaSel() is not available for databinding ...
    > >
    > > What can I do?
    > >
    > > TIA
    > >
    > > Rodrigo Juarez
    > >
    > >
    > >
    > > "Teemu Keiski" <> escribió en el mensaje
    > > news:...
    > >> Hi,
    > >>
    > >> if you create a User Control, you can expose the SelectedValue and

    other
    > >> properties of the DroPDownList from the user control. You can for

    example
    > >> just create another property on the UC. Assuming you already have a
    > >> DropDownList with ID "DropDownList1" in the user control, you could

    have
    > >> a
    > >> property as follows:
    > >>
    > >> public string DdlSelectedValue
    > >> {
    > >> get
    > >> {
    > >> return DropDownList1.SelectedValue;
    > >> }
    > >> set
    > >> {
    > >> DropDownList1.SelectedValue = value;
    > >> }
    > >> }
    > >>
    > >> to expose the DDL's SelectedValue.
    > >>
    > >> If you need more from the DDL, you can expose more properties or even

    the
    > >> DropDOwnList itself entirely with a read-only property.
    > >>
    > >>
    > >> public DropDownList InnerDDL
    > >> {
    > >> get
    > >> {
    > >> return DropDownList1;
    > >> }
    > >> }
    > >>
    > >>
    > >> --
    > >> Teemu Keiski
    > >> ASP.NET MVP, AspInsider
    > >> Finland, EU
    > >> http://blogs.aspadvice.com/joteke
    > >>
    > >>
    > >> "Rodrigo Juarez" <> wrote in message
    > >> news:...
    > >> > Hi
    > >> >
    > >> > I need to create a dropdownlist for reusing in a lot of formviews,

    with
    > >> > databinding.
    > >> >
    > >> > If I create a user control the selectedvalue is not usable for

    > > databinding
    > >> > in formview.
    > >> >
    > >> > Thanks in advance
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >
    > >

    >
    >
     
    Rodrigo Juarez, Mar 2, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nikki
    Replies:
    3
    Views:
    502
    Nikki
    Jul 2, 2003
  2. Axter
    Replies:
    3
    Views:
    3,803
    Richard Herring
    May 13, 2005
  3. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    567
    Chris
    May 19, 2007
  4. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    681
    David Thielen
    Jun 16, 2006
  5. Lagrange
    Replies:
    1
    Views:
    572
    Lagrange
    Jan 17, 2009
Loading...

Share This Page