dynamically adding controls into a datagrid

Posted on 2008-02-03
Medium Priority
Last Modified: 2013-11-26
is there a way to dynamically add a control, especially a custom third party control into an empty datagrid?  

i have tried the following:

    protected void DataBoundHandler(Object objSender, DataGridItemEventArgs e)
        LinkButton link = new LinkButton();
        link.Text = "dsadaa";
        link.Parent = this.MyDataGrid;

during ItemDataBound event, but didn't work

i also tried:


also didn't work, please help.  thanks.
Question by:mmingfeilam
1 Comment

Accepted Solution

hamidovt earned 1500 total points
ID: 20839161

In this example they did quite extreem modifications on the grid.... http://msdn2.microsoft.com/en-us/library/bb498013.aspx 

The idea is to override the Render, reference the table the gridview over there (Table gridTable = (Table)grid1.Controls[0];), create new new GridViewRow, TableCell and afterwards add it to the gridTable...

It is definetely working and I have done that mysefl, but it is rather extreem... If your do not need to have different controls depending on sort(as in example), I would create those controls in the grid with visible false. And in the _RowDataBound get those controls with something like this:
Label lbl1 = (Label)e.Row.FindControl("myLabel1"); and set the visibility to true and if required change the style, content or anything else you want...


Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

587 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