Solved

Add a usercontrol to a templatecolumn which contains a table

Posted on 2004-08-25
7
865 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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