Anybody know how to bind the data to custom control.
ex. i had create a custom control that consist of a TextBox and a Button. how do i tell the aspx to bind the data to the TextBox in custom control like in usual aspx
<asp:TextBox ID="AcNoTextBox" runat="server" Text='<%# Bind("AcNo") %>' />
As per my knowledge you are creating Coposite DataBound Control am i right ?
If you are creating compositeDataBound Control menas you need expose DataTextField and DataValueField , and this control is having CreateChildControl(System.Collections.IEnumerable dataSource, bool dataBinding)
// need to bind here
In above method you need to get the Dag taTextFiled and try to attach the respective value to TextBox.Text property.
If you can explain little bit extra about you control then i will explain clearly .
you are right, it's a composite control. this composite control will have additional function rather than usual textbox and i will put this composite control within Formview/GridView, replacing one of the textbox field. all function within this composite
control has been worked as expected, but i just don't know how to make it bind like Text='<%# Bind("AcNo") %>'. can you show me the example.
thanks for the link, but i am still a little bit confused. to summary it up.
i only need to assign DataSource, DataTextField, DataValueField to the text control in my custom control, and issue DataBind in CreateChildControls event, right ?
Can you more specific?
Let's put it in example,the usual in formview is like in below:
<td align="right"><b>Account No:</b></td>
<td><asp:TextBox ID="AcNoTextBox" RunAt="Server" Text='<%# Bind("AcNo") %>' />
<td align="right"><b>Account Name:</b></td>
<td><asp:TextBox ID="AcNmTextBox" RunAt="Server" Text='<%# Bind("AcNm") %>' />
<td align="right"><b>Account Head:</b></td>
<td><asp:TextBox ID="AcHeadTextBox" RunAt="Server" Text='<%# Bind("AcHead") %>' />
then i am thinking of creating a lookup function which is a compositecontrol (that has a TextBox and a Button),
The Textbox (in compositecontrol) will function to receive value returned from Button Click (which is worked as expected already)
and this textbox will also function as two-way binding (this one i am asking). in this case, to replace AcHeadTextBox.
Hopefully its clear to you.
Based on my experience, if you want to use the 'bind' for the textbox, you should ensure the parent control is template control and have its datasource.
You should create a similar control like the formview, that is to say, the parent control inherit some interface.
Thus you can use the bind method.
The link within the link you given was not not worked as expected. it's already deleted ?