how to override DropDownList.SelectedValue property

  • Thread starter Abraham Andres Luna
  • Start date
A

Abraham Andres Luna

hey everyone,

i have a control that inherits from dropdownlist:

using System;
using System.Web.UI.WebControls;

namespace RDK.WebControls
{
public class SelectedValueDropDown : DropDownList
{
protected override void OnInit(EventArgs E)
{
this.Items.Add(new ListItem("NONE", "NONE"));
}

public override string SelectedValue
{
get
{
return this.SelectedValue;
}
set
{
try
{
this.SelectedValue = value;
}
catch
{
this.SelectedValue = "Error";
}
}
}
}
}


when i try to set the selectedvalue i get a server application unavailable
error page

<%@ Page %>
<script runat="server">
void Page_Load(Object Sender, EventArgs E)
{
ddlWhich.SelectedValue = "ME";
}
</script>
<html>
<head>
<title>Drop Down</title>
</head>
<body>
<form id="frm" runat="server">
<RDK:SelectedValueDropDown id="ddlWhich" runat="server" />
</form>
</body>
</html>


how am i supposed to override/use the selectedvalue property
 
P

Phillip Williams

You should use the keyword "base" instead of "this" in a derived class method
to access the overridden method in the base class, e.g. base.SelectedValue =
value; otherwise you caused an infinite loop.

BTW, the logic you have in the SelectedValue does not make sense (the list
does not have a value named "Error" in it yet you are trying to set it when
trapping an error)
 
A

Abraham Andres Luna

yeah i was setting it to a non-existent value to make sure the trycatch
works
thank you for your answer
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top