Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Control Guru Needed

Reply
Thread Tools

Control Guru Needed

 
 
Joe
Guest
Posts: n/a
 
      01-20-2004
I am having a hard time with setting a property on a custom server
control that i am placing in a repeater. The control inherits from
DropDownList. The property is being set in the repeater using the
DataBinder.Eval method. I can write that value out to the screen,
however, it is not available to the control. I think it is a problem
with the databinding of the repeater making data available to the
custom control too late.

Below is a snippet of how the control is being setup in my aspx page.
After that is the code for my control. I've tried to set that
DefaultProperty in 2 different places but can't think of anything
else.

----------------------------------
ASPX
----------------------------------

<asp:repeater id=rpt DataSource="<%#dt%>" Runat="server">

<ItemTemplate>
<frmControl:ControlTypeDropDown id="ddControl" runat="server"
DefaultValue='<%#DataBinder.Eval(Container.DataIte m,
"controlTypeId")%>' /><Br>
</ItemTemplate>
</asp:Repeater>

----------------------------------
Server Control
----------------------------------

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Web.UI.WebControls;
using System.Collections;

namespace app.Controls
{

/// <summary>
/// A server control to display the dropdown of Control Types. Will
be
/// displayed programatically in a repeater.
/// </summary>
public class ControlTypeDropDown :
System.Web.UI.WebControls.DropDownList
{

private string defaultValue;
public string DefaultValue
{
get{return defaultValue;}
set{defaultValue=value;}
}

public ControlTypeDropDown() : base(){}


protected override void OnInit(System.EventArgs e)
{

if(base.EnableViewState && !Page.IsPostBack)
{
//If using ViewState, only DataBind the FIRST time the page is
loaded.
this.DataBind();

}
else if(!base.EnableViewState && !Page.IsPostBack)
{
//If not using ViewState, DataBind EVERY time the page is loaded.
//Setup();
this.DataBind();
}



}



protected override void RenderContents(System.Web.UI.HtmlTextWriter
writer)
{
if(DefaultValue != null && DefaultValue != "")
{
base.Items.FindByValue(DefaultValue).Selected=true ;
}

base.RenderContents(writer);



}

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if(DefaultValue != null && DefaultValue != "")
{
base.Items.FindByValue(DefaultValue).Selected=true ;
}

base.Render(writer);
}

protected override void OnLoad(System.EventArgs e)
{
if(base.EnableViewState)
base.DataBind();

base.Attributes.Add("onChange", "openWin(this)");
}




public override void DataBind()
{
SortedList ht;
if(HttpContext.Current.Application["ControlTypeDropDown"]==null)
{
TS s = new TS();
ht = s.GetFormControls();

HttpContext.Current.Application.Add("ControlTypeDr opDown", ht);
}
else
{

ht = (SortedList)HttpContext.Current.Application["ControlTypeDropDown"];
}

base.DataSource = ht;
base.DataTextField = "value";
base.DataValueField = "key";
base.DataBind();

}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IT Job Guru - Certification Guru Rohit A+ Certification 0 08-13-2008 07:31 PM
ASP.NET Image Upload... Guru needed John Thompson ASP .Net 1 06-30-2004 07:22 AM
Control Guru Needed Joe ASP .Net Web Controls 0 01-20-2004 02:45 AM
Control Guru Needed Joe ASP .Net Building Controls 0 01-20-2004 02:43 AM
Language and Direction real GURU needed! (Hebrew and maybe arabic) CR or Charset issue? Efy. ASP .Net 2 06-25-2003 03:28 PM



Advertisments