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

Dynamic Grid with Textboxes

1 Answer 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 13 Jan 2014, 09:09 PM

Hey, I have a grid being created dynamically from a manually built pivot table with includes a variable number of columns and a variable number of rows.


I've gotten it to display statically quite easily, but what I would like to be able to do is replace the static numbers with a textbox containing the numeric value for each column for each view.  And then be able to iterate through those rows on a click event to save any changed data.


A visual of the gridview is attached.

Super simple code right now:
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemCreated="RadGrid1_ItemCreated" >
   
    </telerik:RadGrid>

Code behind - all the hard work is done in creating a dynamic pivot table (dt):
RadGrid1.DataSource = dt;
RadGrid1.DataBind();


I've got code in the ItemCreated event to try to create a textbox, but this code is not working:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               DataRowView drv = (DataRowView)e.Item.DataItem;
 
               TextBox txt = new TextBox();
               txt.Text = drv[0].ToString();
               e.Item.Cells[0].Controls.Add(txt);
 
           }
       }


Thanks!!

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 16 Jan 2014, 04:21 PM
Hi Angie,

Could you please elaborate a bit more on the exact functionality you need to achieve sop that we could suggest the best option for your case?
In order to easily add RadTextBox control into RadGrid item you could simply add a GridTemplateColumn and add the required controls in it.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Angie
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or