Binding an ASCX?

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have an ASCX (I think thats called a user control), with a public
property of "TextStatic".

I want to put this ASCX into a datagrid's template item and bind a
data sources to the TextStatic property.

Is there any way to do this? I tried setting <Bindable(true)> to the
property, but that didn't seem to make the "TextStatic" property
showup in the Bindable properties of the ASCX.

Any idea?
 
HI,

First, I don’t think that usercontrol should serve as datasource. It’s
better to create dedicate class as the dataprovider. Anyway in order to
supply data to datagrid your class should implement the
System.Collections.IEnumerable interface.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Thanks for the reply, but I think you are misunderstanding what I am
trying to do.

Say you have a datagrid. You can put a textbox into the ItemTemplate
for a row of the datagrid, and bind the "Text" property of the textbox
to the datasource.

This is what I want to do, but instead of using a textbox and "Text" I
want to use my ASCX control and "TextStatic", but when I put my ASCX
into the item template and go into the Bindings dialog, there are no
values that I can select to assign for binding (Such as "Text" or
"TextStatic").

Does that make sense?
 
Yes it makes sense, Sorry.

Basically you just need to add property. it works fine with win forms
but not with web forms (as you say). I'm trying to figure it up.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Hi,
Still struggling but I just want to make sure that you aware that you
can bind the user control property without the visual designer:

<asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 44px;
POSITION: absolute; TOP: 217px" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<uc1:WebUserControl1 id=WebUserControl11 runat="server"
MyText='<%# DataBinder.Eval(Container.DataItem, "Val") %>'>
</uc1:WebUserControl1>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Back
Top