Solved

Add a usercontrol to a templatecolumn which contains a table

Posted on 2004-08-25
7
860 Views
Last Modified: 2008-01-09
Hi Experts,

Here is my code to create my datagrid template column:

public class MediasColumn : ITemplate
{
    public void InstantiateIn(System.Web.UI.Control container)
    {
        Table tableParent=new Table();
        tableParent.ID="TableParent";
        TableRow tableRowParentMaster=new TableRow();
        TableCell tableCellParentMaster=new TableCell();

// Here, I want to add a usercontrol to my table. How can I do ?

         container.Controls.Add(tableParent);
    }
}

Thanks.
0
Comment
Question by:noulouk
  • 3
  • 2
7 Comments
 
LVL 21

Expert Comment

by:tovvenki
ID: 11899508
Hi,
did you tried using LoadControl like

Table tableParent=new Table();
tableParent.ID="TableParent";
TableRow tableRowParentMaster=new TableRow();
TableCell tableCellParentMaster=new TableCell();

Control c1 = LoadControl("MyUserControl.ascx");
((MyUserControl)c1).BackColor = "beige";
tableCellParentMaster.Controls.Add(c1)
container.Controls.Add(tableParent);


regards,
venki
0
 
LVL 9

Author Comment

by:noulouk
ID: 11900837
venki,

this code works in a Page, but I can't make it work in my template column.

Do you know how to do ?
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 11901082
Hi,
how are you adding the template columns? can you paste some code here?

regards,
venki
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Author Comment

by:noulouk
ID: 11901148
Here is what you want:

TemplateColumn templateColumn=new TemplateColumn();
MediasColumn mediasColumn=new MediasColumn();
templateColumn.ItemTemplate=mediasColumn;
MyDataGrid.Columns.Add(templateColumn);


The real problem is that I want to add a usercontrol programmatically to my datagrid:
I try previous solution and also
templateColumn.ItemTemplate=LoadTemplate("MediasTemplate.ascx");

I found some articles about how to add a template column to a datagrid from a usercontrol, but those articles don't describe how to retrieve the usercontrol in the itemdatabound event of the datagrid. You know I'm not new in .Net and so I set the ID of my usercontrol, but I can't find my usercontrol with e.Item.FindControl("MyusercontrolId") .

Thanks for helping me. Hope you understand what I try to do.
0
 
LVL 9

Author Comment

by:noulouk
ID: 11935042
I found the solution : I use (myUserControl)e.Item.Controls[0].Controls[0] . Why : I don't know really .
Thanks tovvenki .
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 12094518
Closed, 500 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now