Solved

Add a usercontrol to a templatecolumn which contains a table

Posted on 2004-08-25
7
862 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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