Creating a reusable dropdownlist for use in formview

R

Rodrigo Juarez

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
 
T

Teemu Keiski

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;
}
}
 
R

Rodrigo Juarez

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
 
R

Rodrigo Juarez

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
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top