WebControls


Z

Zürcher See

I created a webcontrol with inside a dropdownlist, and exposed its
proprieties DataSource,DataMember,DataTextField,DataValueField
But I can't set the DataSource from the aspx page
(DataSource='<%#this.DataSource%>' ). If I set a breakpoint inside the
DataSet propriety, I see that
the thread never reach this point, the DataSource propriety will never be
called. Why?

<%@ Register TagPrefix="wcl" Namespace="WebControlLibrary1"
Assembly="WebControlLibrary1" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="WebProject1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout"
xmlns:wcl="urn:http://schemas.myCompany.org/myTechnology">
<form id="Form1" method="post" runat="server">
&nbsp;
<wcl:WebCustomControl1 id="WebCustomControl11"
DataSource='<%#this.DataSource%>' DataMember="ddl" DataTextField="text"
DataValueField="value" style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute;
TOP: 48px"
runat="server"></wcl:WebCustomControl1>
</form>
</body>
</HTML>


namespace WebProject1
{
public class WebForm1 : System.Web.UI.Page
{
protected WebControlLibrary1.WebCustomControl1 WebCustomControl11;
private System.Data.DataSet ds;

private void Page_Load(object sender, System.EventArgs e)
{
if(Session["StoreData"] == null)
{
DataRow dr;
ds=new DataSet();
DataTable t=new DataTable("ddl");
t.Columns.Add(new DataColumn("value",typeof(int)));
t.Columns.Add(new DataColumn("text",typeof(string)));
t.Rows.Add(new object[]{1,"one"});
t.Rows.Add(new object[]{2,"two"});
t.Rows.Add(new object[]{3,"three"});
t.Rows.Add(new object[]{4,"four"});
this.ds.Tables.Add(t);
Session["StoreData"] = ds;
}
else ds=(DataSet)Session["StoreData"];
}

public DataSet DataSource
{
get{return this.ds;}
}
}
}

namespace WebControlLibrary1
{
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{
private System.Web.UI.WebControls.DropDownList _dropDownList=new
DropDownList();

public object DataSource
{
get{return this._dropDownList.DataSource;}
set{this._dropDownList.DataSource=value;}
}

public string DataMember
{
get{return this._dropDownList.DataMember;}
set{this._dropDownList.DataMember=value;}
}

public string DataTextField
{
get{return this._dropDownList.DataTextField;}
set{this._dropDownList.DataTextField=value;}
}

public string DataValueField
{
get{return this._dropDownList.DataValueField;}
set{this._dropDownList.DataValueField=value;}
}

protected override void Render(HtmlTextWriter output)
{
this._dropDownList.DataBind();
this._dropDownList.RenderControl(output);
}
}
}
 
Ad

Advertisements

K

Kenneth

Hello:
i donot think so the DataSource propriety can be writen in .aspx page.


Zürcher See said:
I created a webcontrol with inside a dropdownlist, and exposed its
proprieties DataSource,DataMember,DataTextField,DataValueField
But I can't set the DataSource from the aspx page
(DataSource='<%#this.DataSource%>' ). If I set a breakpoint inside the
DataSet propriety, I see that
the thread never reach this point, the DataSource propriety will never be
called. Why?

<%@ Register TagPrefix="wcl" Namespace="WebControlLibrary1"
Assembly="WebControlLibrary1" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="WebProject1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout"
xmlns:wcl="urn:http://schemas.myCompany.org/myTechnology">
<form id="Form1" method="post" runat="server">
&nbsp;
<wcl:WebCustomControl1 id="WebCustomControl11"
DataSource='<%#this.DataSource%>' DataMember="ddl" DataTextField="text"
DataValueField="value" style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute;
TOP: 48px"
runat="server"></wcl:WebCustomControl1>
</form>
</body>
</HTML>


namespace WebProject1
{
public class WebForm1 : System.Web.UI.Page
{
protected WebControlLibrary1.WebCustomControl1 WebCustomControl11;
private System.Data.DataSet ds;

private void Page_Load(object sender, System.EventArgs e)
{
if(Session["StoreData"] == null)
{
DataRow dr;
ds=new DataSet();
DataTable t=new DataTable("ddl");
t.Columns.Add(new DataColumn("value",typeof(int)));
t.Columns.Add(new DataColumn("text",typeof(string)));
t.Rows.Add(new object[]{1,"one"});
t.Rows.Add(new object[]{2,"two"});
t.Rows.Add(new object[]{3,"three"});
t.Rows.Add(new object[]{4,"four"});
this.ds.Tables.Add(t);
Session["StoreData"] = ds;
}
else ds=(DataSet)Session["StoreData"];
}

public DataSet DataSource
{
get{return this.ds;}
}
}
}

namespace WebControlLibrary1
{
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{
private System.Web.UI.WebControls.DropDownList _dropDownList=new
DropDownList();

public object DataSource
{
get{return this._dropDownList.DataSource;}
set{this._dropDownList.DataSource=value;}
}

public string DataMember
{
get{return this._dropDownList.DataMember;}
set{this._dropDownList.DataMember=value;}
}

public string DataTextField
{
get{return this._dropDownList.DataTextField;}
set{this._dropDownList.DataTextField=value;}
}

public string DataValueField
{
get{return this._dropDownList.DataValueField;}
set{this._dropDownList.DataValueField=value;}
}

protected override void Render(HtmlTextWriter output)
{
this._dropDownList.DataBind();
this._dropDownList.RenderControl(output);
}
}
}
 
Ad

Advertisements

Z

Zürcher See

If you place a DropDownList on the page, not in a WebControl, you can set
the DataSource and it works fine.
But if I plate the DropDownList in a WebControl it does not work anymore

Kenneth said:
Hello:
i donot think so the DataSource propriety can be writen in .aspx page.


Zürcher See said:
I created a webcontrol with inside a dropdownlist, and exposed its
proprieties DataSource,DataMember,DataTextField,DataValueField
But I can't set the DataSource from the aspx page
(DataSource='<%#this.DataSource%>' ). If I set a breakpoint inside the
DataSet propriety, I see that
the thread never reach this point, the DataSource propriety will never be
called. Why?

<%@ Register TagPrefix="wcl" Namespace="WebControlLibrary1"
Assembly="WebControlLibrary1" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="WebProject1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout"
xmlns:wcl="urn:http://schemas.myCompany.org/myTechnology">
<form id="Form1" method="post" runat="server">
&nbsp;
<wcl:WebCustomControl1 id="WebCustomControl11"
DataSource='<%#this.DataSource%>' DataMember="ddl" DataTextField="text"
DataValueField="value" style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute;
TOP: 48px"
runat="server"></wcl:WebCustomControl1>
</form>
</body>
</HTML>


namespace WebProject1
{
public class WebForm1 : System.Web.UI.Page
{
protected WebControlLibrary1.WebCustomControl1 WebCustomControl11;
private System.Data.DataSet ds;

private void Page_Load(object sender, System.EventArgs e)
{
if(Session["StoreData"] == null)
{
DataRow dr;
ds=new DataSet();
DataTable t=new DataTable("ddl");
t.Columns.Add(new DataColumn("value",typeof(int)));
t.Columns.Add(new DataColumn("text",typeof(string)));
t.Rows.Add(new object[]{1,"one"});
t.Rows.Add(new object[]{2,"two"});
t.Rows.Add(new object[]{3,"three"});
t.Rows.Add(new object[]{4,"four"});
this.ds.Tables.Add(t);
Session["StoreData"] = ds;
}
else ds=(DataSet)Session["StoreData"];
}

public DataSet DataSource
{
get{return this.ds;}
}
}
}

namespace WebControlLibrary1
{
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{
private System.Web.UI.WebControls.DropDownList _dropDownList=new
DropDownList();

public object DataSource
{
get{return this._dropDownList.DataSource;}
set{this._dropDownList.DataSource=value;}
}

public string DataMember
{
get{return this._dropDownList.DataMember;}
set{this._dropDownList.DataMember=value;}
}

public string DataTextField
{
get{return this._dropDownList.DataTextField;}
set{this._dropDownList.DataTextField=value;}
}

public string DataValueField
{
get{return this._dropDownList.DataValueField;}
set{this._dropDownList.DataValueField=value;}
}

protected override void Render(HtmlTextWriter output)
{
this._dropDownList.DataBind();
this._dropDownList.RenderControl(output);
}
}
}
 

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

Top