?
Solved

Add a usercontrol to a templatecolumn which contains a table

Posted on 2004-08-25
7
Medium Priority
?
869 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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