Base Web/HTML control?

  • Thread starter Thread starter Kelmen Wong
  • Start date Start date
K

Kelmen Wong

Greeting,

I'm working on a routine that dynamically locate a html/web control
using FindControl(), then perform some manipulation like bind a
datatable onto the control.DataSource.

switch(objCtrl.GetType().Name)
{
case "HtmlSelect":
HtmlSelect objHtmlSelect = (HtmlSelect)objCtrl;

if(drowBlankVal != null)
{
drowBlankVal[objHtmlSelect.DataValueField] = "";
drowBlankVal[objHtmlSelect.DataTextField] = strBlankValTxt;
dtblList.Rows.InsertAt(drowBlankVal, 0);
}

objHtmlSelect.DataSource = dtblList;
objHtmlSelect.DataBind();
objHtmlSelect = null;
break;

I wanna write a function to do the binding, problem is the control
class is dynamic, and I can't and unsuccessful to typecast them to any
generic/base control that have the property DataSource and DataBind().

Anyone got any better way for this one?
 
Hi Kelmen,

Unfortunally what you want is not possible, if you see the base class of
webcontrols and html controls is System.Web.UI.Control and it does not
implement a binding feature. in fact there is not aa IBindable interface
in.NET , why not I have no idea. it may be cause the binding mechanism work
different depending of the control that you are binding to.

One example, if you are using DropDownList ( or any
System.Web.UI.WebControls.ListControl ) apart of setting the DataSource
property as you always have, you will have to especify the DataValueField
and DataTextField , this is not needed for another control, like a TextBox
for example.



I'm afraid that you will have to test for each control :(

Merry X-Mas,
 
I missed the "simple" late-binding feature of the VB. Just create the
whatever instances and call whatever mth/prop you want.
 
Back
Top