473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Include a usercontrol in a table

Hi,

This question is related with c# and ASP.NET, (I could't find the rigth
forum).

What I need to do is to add a usercontrol in a row of my table using the
server code (I know how to do it on the front-end). The idea is to show the
search results on the page, every entry is a usercontrol (obviously the same
loaded with different data). I have tried this but it does not work, any
ideas? (here is an example)

protected MyUserControl[] m_MyControls;
protected Table m_MyTable;
public void On_Load(...)
{
MyControls = new MyUserControl[2];
MyControls[0] = new MyUserControl() ;
MyControls[1] = new MyUserControl() ;

MyControl[0].Description = "Text1";
MyControl[1].Description = "Text2";

MyTable.Rows[0].Cells[0].Controls.Add(M yControl[0]);
MyTable.Rows[0].Cells[0].Controls.Add(M yControl[1]);
}

No errors are triggered, seems to be adding the controls but no ouput is
visible (none even using "View source").

Any Ideas?
Thanks


--
Salvador Alvarez Patuel
Exony Ltd - London, UK
Nov 17 '05 #1
2 1607
Hi,

"Salvador" <Sa******@discu ssions.microsof t.com> wrote in message
news:3A******** *************** ***********@mic rosoft.com...
Hi,

This question is related with c# and ASP.NET, (I could't find the rigth
forum).
microsoft.publi c.dotnet.framew ork.aspnet will do
What I need to do is to add a usercontrol in a row of my table using the
server code (I know how to do it on the front-end). The idea is to show
the
search results on the page, every entry is a usercontrol (obviously the
same
loaded with different data). I have tried this but it does not work, any
ideas? (here is an example)


You can't do it like that, first of all what is wrong with doing it in the
aspx page? ( I assume you refer to this when you talk about the front-end) ?
I always do it like that, you have all the grid declaration in the aspx
page

In case you dont want to do it for some reason the solution is intercept the
DataGrid.ItemDa taBound event. it does fire when the grid is binding the
datasource.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nov 17 '05 #2
Hi,

Thanks for the reply,
the problem that I have is that my user control is the entity, I don't know
how many I have to render until the page is processed (sorry, is my first
project in aspnet)

So, if I have it on the aspx page I will have (generic code)

<table>
<row>
<cell>
<MyHeader:MyUse rControl Id = "MyName" runat ="server"/>
</cell>
</row>
</table>

This works great for a single instance but I want several, the result on
html has to be something like this:

<cell>
<MyHeader:MyUse rControl Id = "MyName" runat ="server"/>
<MyHeader:MyUse rControl Id = "MyNamex" runat ="server"/>
<MyHeader:MyUse rControl Id = "MyNamexx" runat ="server"/>
<MyHeader:MyUse rControl Id = "MyNamexxx" runat ="server"/>
</cell>

The amount of them is dynamic, that's why I am creating several instances of
the user control on the server code. To do an analogy, is like creating a
data repeater where the individual content is a usercontrol.

Hope this makes sense :)

Salva


--
Salvador Alvarez Patuel
Exony Ltd - London, UK
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Salvador" <Sa******@discu ssions.microsof t.com> wrote in message
news:3A******** *************** ***********@mic rosoft.com...
Hi,

This question is related with c# and ASP.NET, (I could't find the rigth
forum).


microsoft.publi c.dotnet.framew ork.aspnet will do
What I need to do is to add a usercontrol in a row of my table using the
server code (I know how to do it on the front-end). The idea is to show
the
search results on the page, every entry is a usercontrol (obviously the
same
loaded with different data). I have tried this but it does not work, any
ideas? (here is an example)


You can't do it like that, first of all what is wrong with doing it in the
aspx page? ( I assume you refer to this when you talk about the front-end) ?
I always do it like that, you have all the grid declaration in the aspx
page

In case you dont want to do it for some reason the solution is intercept the
DataGrid.ItemDa taBound event. it does fire when the grid is binding the
datasource.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1209
by: Pete | last post by:
I am building an ASP.NET application and have just encountered something very strange which I would like explained if possible. In BaseForm.ascx I have the following <form> element: <form ID="formBaseForm" method="post" runat="server"> <!-- Banner UserControl --> <PW:Banner runat="server" ID="Banner1" /> <!-- Initial UserControl -->
2
2673
by: bill yeager | last post by:
When trying to run my web project, I get the following error: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The base class includes the
1
314
by: al | last post by:
Greetings, I included a UserControl (UC)on webpage. It works fine except when I change document direction to 'rtl', UC doesn't resize with the rest of document. It just disappears behinde rest of document(textbox, labesl...etc)? Any idea/s?? Usually, what is the best way of placing UC in a webpage? In a
0
980
by: Diego | last post by:
Hallo! I have an HtmlTable with a UserControl into it. Setting table.Visible = false all controls in table have .Visible = false. Then, setting table.Visible = true all controls in table except the usercontrol hav .Visible = true; the usercontrol.Visible is still false. Is this a bug? Is documented? What's wrong?
12
2216
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
3
1602
by: Larry | last post by:
Hi, I need a method to dynamically include a server side include in my asp.net page. The problem is, the include file contains asp.net controls, and I can't find a way to get the controls to render. HISTORY I have an active website. I have about 100 include files that are just html text. In .aspx page, I have the following:
0
1147
by: Arpan | last post by:
I have created the following UserControl (the file is named LoginForm.ascx): <script language=VB runat="server"> Public UName As String Public UPwd As String Public BColor As String Public Sub btnSubmit(ByVal obj As Object, ByVal ea As EventArgs) lblMessage.Text = "UserName : " & uid.Text & "<br>Password : "
6
12144
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use binding like normal. The problem I am running into is that my UserControl ends up with a different BindingContext then the ParentForm it is contained in and thus all other controls on the parent form. (I want various controls on the form to...
2
1555
by: Academia | last post by:
I want to include a button that opens a .chm help file on a usercontrol. I haven't yet looked at how the button is to open the help but before I go there I need to know how to include the .chm file with the usercontrol so that it will be available where ever the control is used. Does anyone know how to include the file? Thanks
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.