[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Add a usercontrol to a templatecolumn which contains a table

Posted on 2004-08-25
7
Medium Priority
?
870 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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