This is a migrated thread and some comments may be shown as answers.

Create TextBox into a Grid in Server Side

6 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrés David Santacoloma Isaza
Top achievements
Rank 1
Andrés David Santacoloma Isaza asked on 14 Apr 2011, 04:44 PM
Hi:
I need create a textbox into a gridcolumn, but it's dinamic in with c# code.
Thanks
David.

6 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 19 Apr 2011, 04:09 PM
Hi Andrés,

You can add the texbox in the ItemCreated event of the grid. It is fired for all items and the you can find the specific cell in which to add the textbox.

Find more information on accessing grid cells and rows in the below article:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Greetings,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Andrés David Santacoloma Isaza
Top achievements
Rank 1
answered on 25 Apr 2011, 03:40 PM
Hi:

It's confuse for me.
I have the following code:

 

RadGrid MiRadGrid = new RadGrid();

 

 

 

TemplateColumn MiColumna = new TemplateColumn();

 

 

 

TextBox MiTextBox = new TextBox();

 

 

MiTextBox.ID =

"MiTextBox";

 

 

MiColumna.ItemTemplate = MiTextBox; //Error

 

MiRadGrid.Columns.Add(MiColumna);

It shows an error, and I don't know solve.

Thanks.

0
Princy
Top achievements
Rank 2
answered on 26 Apr 2011, 06:09 AM
Hello,

Try the following snippet code. Hope it helps you.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem Item = (GridDataItem)e.Item;
           TableCell cell = Item["EmpId"];
           TextBox txtBox = new TextBox();
           txtBox.ID = "Txt1";
           cell.Controls.Add(txtBox);
        }
    }

Also refer the following help article.
Programmatic creation

Thanks,
Princy
0
Han
Top achievements
Rank 1
answered on 16 Feb 2012, 10:50 PM

Hello Princy,

I follow your code to create a dynamic textbox from the radgrid_ItemDataBound.  In my case, by default I set the display property to false.  How do I change the property display to true when user click on a different radgrid_SelectedIndexChanged?  Please see my code below:

 protected void scheduleRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem note = (GridDataItem)e.Item;
            TableCell cell = note["Note"];
            RadTextBox txtBox = new RadTextBox();
            txtBox.ID = "txtNote";
            txtBox.Width = 500; //or Unit.Pixel(500)
            txtBox.MaxLength = 1000;
            txtBox.TextMode = InputMode.MultiLine;
            cell.Controls.Add(txtBox);
            txtBox.Display = false;
           
        }
    }
and I want to turn the textbox display = true from here:
  protected void doctorRadGrid_SelectedIndexChanged(object sender, EventArgs e)
    {
             foreach (GridDataItem gridItem in scheduleRadGrid.Items)
                    {
                        ((RadTextBox)gridItem.FindControl("txtNote")).Display = true;
                    }
}
but it's not working.  Please help!  thanks a lot!

0
Shinu
Top achievements
Rank 2
answered on 17 Feb 2012, 04:54 AM
Hello Han,

You should create the controls in ItemCreated event handler. Also check the following help documentation.
Distinguishing the major differences between ItemCreated and ItemDataBound events

-Shinu.
0
Han
Top achievements
Rank 1
answered on 17 Feb 2012, 03:32 PM
Thank you so much! :-)  It works now. You and your team have a good weekend.

Han
Tags
Grid
Asked by
Andrés David Santacoloma Isaza
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Andrés David Santacoloma Isaza
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Han
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or